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

本站现有博文324篇,共被浏览808320

本站已经建立2510天!

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