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

本站现有博文338篇,共被浏览966861次

本站已经建立2679天!

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