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

本站现有博文323篇,共被浏览795676

本站已经建立2493天!

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