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

本站现有博文322篇,共被浏览790245

本站已经建立2486天!

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