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

本站现有博文327篇,共被浏览826001

本站已经建立2532天!

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