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

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

本站已经建立2464天!

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