您的位置:首页 > 其它

你绝对想不到的程序输出结果

2013-10-04 20:51 204 查看
1.第一题

#include <stdio.h>

#include <stdlib.h>

#include<iostream>

using namespace std;

int main()

{

    int i=43;

    printf("%d\n",printf("%d",printf("%d",i))); 
system("pause");
 return 0;

}

简直不敢相信,程序会输出4321,你知道为什么吗?要知道为什么,你需要知道printf的返回值是什么。printf返回值是输出的字符个数

2.第二题

#include <stdio.h>

#include <stdlib.h>

#include<iostream>

using namespace std;

int main()

{

    int a=1;     

    switch(a)     

    {  

        int b=20;         

        case 1:

            printf("b is %d\n",b);

            break;

        default:

            printf("b is %d\n",b);

            break;

    }
system("pause");
 return 0;

}

这个会报错了,不可以在switch里初始化啊,会直接跳过给b赋值的语句呢!

3. 第三题

#include <stdio.h>

#include <stdlib.h>

#include<iostream>

using namespace std;

int main()

{

   int i;

    i = 10;

    printf("i : %d\n",i);

    printf("sizeof(i++) is: %d\n",sizeof(i++));

    printf("i : %d\n",i);
system("pause");
 return 0;

}

不会输出10,4,,11哦,因为sizeof不是一个函数,是一个操作符,其求i++的类型的size,这是一件可以在程序运行前(编译时)完全的事情,所以,sizeof(i++)直接就被4给取代了,在运行时也就不会有了i++这个表达式。

.............未完待续
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐