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

本站现有博文330篇,共被浏览860792

本站已经建立2569天!

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