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

本站现有博文340篇,共被浏览1019323次

本站已经建立2719天!

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