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

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

本站已经建立2611天!

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