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

本站现有博文320篇,共被浏览756835

本站已经建立2421天!

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