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

本站现有博文328篇,共被浏览841149

本站已经建立2546天!

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