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

本站现有博文321篇,共被浏览764894

本站已经建立2443天!

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