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

本站现有博文311篇,共被浏览742158

本站已经建立2381天!

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