zoukankan      html  css  js  c++  java
  • C语言

    版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/u012515223/article/details/26719135

    printf的占位符(%) 异常


    本文地址: http://blog.csdn.net/caroline_wendy/article/details/26719135


    C语言中, 使用%代表占位符的意思, 如%d代表int类型, %f代表float类型.

    须要注意的是, 占位符须要和使用參数匹配, 否则会出现越界或截断的情况;

    如%f, 匹配5, 会导致使用8个字节去匹配4个字节, 会产生越界, 输出0;

    %d, 匹配5.01, 会导致使用4个字节去匹配8个字节, 会产生截断, 输出一个大数;


    代码:

    /*
     * test.cpp
     *
     *  Created on: 2014.05.23
     *      Author: Spike
     */
    
    /*eclipse cdt, gcc 4.8.1*/
    
    #include <stdio.h>
    
    int main()
    {
    	printf("%f
    ", 5);
    	printf("%d
    ", 5.01);
    }
    

    输出:

    0.000000
    1889785610
    




  • 相关阅读:
    python返回函数与匿名函数
    Session&Cookie
    write RE validation
    hello2 source anaylis
    Filter
    Development descriptor
    web.xml配置详解
    Annotation
    injector
    container
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10780396.html
Copyright © 2011-2022 走看看