你绝对想不到的程序输出结果
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++这个表达式。
.............未完待续
#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++这个表达式。
.............未完待续
相关文章推荐
- 写出如下程序的输出结果
- .Net ( C# ) 调用控制台程序并取得输出结果
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- 程序从命令行接收多个数字,求和之后输出结果。
- 为什么程序运行的结果,虽然是倒序输出了,但是有输出了一串别的汉字
- 第12周项目1(3)-阅读有递归函数的程序并输出结果
- 编制一个完成两个数的四则运算程序。如:用户输入34+56则输出结果90.00。要求运算结果保留两位小数,用户输入时一次将两个数和操作符输入。
- 能猜出这段程序的输出结果吗?
- 文章标题编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。
- 机试题:过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- 把程序的输出结果输出到log文件
- 编一个程序,从 string 对象中去掉标点符号。要求输入到程序的字符串必须含有标点符号,输出结果则是去掉标点符号后的 string 对象。
- 程序从命令行接收多个数字,求和之后输出结果。
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- 第12周项目1(3)-阅读有递归函数的程序并输出结果
- 华为机试通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。例如:1 + 2 + 34–5 + 67–8 + 9 = 100。
- Java程序片段与java表达式(将结果以表格的形式输出)
- 请各位帮忙看一下,第一个程序为什么不能输出和第二个程序一样的结果?这两个程序只有求最大公约束的代码不同