EADST

C printf Usage Guide

C printf Usage Guide

Code

 # include < stdio.h>

int main() {
    // Integer
    int intValue = 42;
    printf("Integer (%%d): %d\n", intValue);

    // Float/Double
    double doubleValue = 3.14159;
    printf("Float/Double (%%f): %f\n", doubleValue);

    // Character
    char charValue = 'A';
    printf("Character (%%c): %c\n", charValue);

    // String
    const char* stringValue = "Hello";
    printf("String (%%s): %s\n", stringValue);

    // Hexadecimal
    int hexValue = 255;
    printf("Hexadecimal (%%x): %x\n", hexValue);

    // Pointer
    int variable = 100;
    printf("Pointer (%%p): %p\n", (void*)&variable);

    // Additional examples showing formatting options
    printf("\n--- Formatting Examples ---\n");
    printf("Right-aligned (%%10d): '%10d'\n", intValue);
    printf("Left-aligned (%%-10d): '%-10d'\n", intValue);
    printf("Precision (%%0.2f): %0.2f\n", doubleValue);
    printf("Width and precision (%%8.2f): '%8.2f'\n", doubleValue);
    printf("Zero-padded (%%05d): %05d\n", intValue);

    return 0;
}

Output

Integer (%d): 42
Float/Double (%f): 3.141590
Character (%c): A
String (%s): Hello
Hexadecimal (%x): ff
Pointer (%p): 0x7ffeeb3a1b0c (this address will vary)

--- Formatting Examples ---
Right-aligned (%10d): '        42'
Left-aligned (%-10d): '42        '
Precision (%0.2f): 3.14
Width and precision (%8.2f): '    3.14'
Zero-padded (%05d): 00042
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Dataset Food Vmess 顶会 Math WAN C++ GGML Cloudreve Template logger Web TSV v0.dev Translation Quantize Vim FP8 Pillow scipy OpenCV DeepSeek Django OpenAI Python Pytorch Hotel 论文速读 Ubuntu Knowledge 搞笑 HuggingFace tar Google LLM FP32 git-lfs Tiktoken COCO Nginx Jupyter 论文 SPIE BF16 TTS PDF ResNet-50 Pickle Hilton PyCharm Use LLAMA diffusers Qwen2.5 域名 AI XGBoost Linux Firewall 阿里云 Heatmap Search RAR Llama 版权 Bin FP16 第一性原理 DeepStream 飞书 Proxy Datetime Color llama.cpp Image2Text Plotly Paper YOLO Input 腾讯云 Random 算法题 关于博主 ModelScope XML uWSGI git Conda CSV Shortcut VPN ms-swift 签证 Data Hungarian PyTorch Base64 Qwen2 RGB InvalidArgumentError BeautifulSoup CAM UI CEIR ONNX GPTQ FlashAttention Qwen Disk UNIX Rebuttal News Git Claude Jetson Transformers Docker CV Distillation Attention icon 强化学习 NLTK Land EXCEL Breakpoint uwsgi Magnet Zip GIT Freesound Plate NameSilo 多线程 Algorithm Sklearn PIP OCR Safetensors Bipartite Video LoRA CLAP RL Interview Password Bert Baidu Statistics Github 证件照 净利润 报税 Permission Domain NLP Markdown Numpy IndexTTS2 公式 Diagram GoogLeNet TensorRT Mixtral hf API Crawler Card Pandas Gemma TensorFlow 递归学习法 MD5 图标 SAM HaggingFace JSON ChatGPT Ptyhon Augmentation Logo Review BTC LeetCode SVR QWEN Streamlit LaTeX Tracking CUDA Miniforge v2ray Tensor Website GPT4 WebCrawler Quantization CTC Animate tqdm Anaconda Windows SQLite VSCode 音频 CC PDB SQL 多进程 财报 Agent FastAPI Michelin Bitcoin FP64 Paddle torchinfo VGG-16 printf Clash 继承 mmap Excel 云服务器 transformers 图形思考法
站点统计

本站现有博文333篇,共被浏览924634

本站已经建立2631天!

热门文章
文章归档
回到顶部