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

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

本站已经建立2538天!

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