上述计划的产出是多少? [英] What is the Output of above Program ?
本文介绍了上述计划的产出是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void main()
{
int x=5,y=10;
swap2(x,y);
printf("%d %dn",x,y)
swap2(x,y);
printf("%d %dn",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
推荐答案
这一切都取决于swap2
函数定义。例如,如果定义swap2
函数用于销毁Universe,那么程序将突然终止。
以下C
程序
It all depends onswap2
function definition. If, for instance, theswap2
function is defined for destroying the Universe then the program would abruptly terminate.
The followingC
program
#include <stdio.h>
int main()
{
int x = 5, y = 10;
swap2(x, y);
printf("%d, %d\n", x, y);
swap2(x, y);
printf("%d, %d\n", x, y);
return 0;
}
将始终输出
Will always output
5, 10
5, 10
用于swap2函数的任何正确实现,因为swap2原型必须是
for any correct implementation of the swap2 function, since the swap2 prototype must be
void swap(int x, int b);
(实际上你可以使用另一种类型作为返回值)。
在 C ++
编程语言情景可能会改变,定义,例如, swap2
这种方式
(actually you can use another type for return value).
In C++
programming language the scenario may change, defining, for instance, swap2
this way
void swap2( int & a, int & b)
{
int t = a;
a = b;
b = t;
}
您能猜出实际输出吗?
Could you guess the actual output?
运行它,并且找出来。
我们不能 - 我们没有你的swap2
函数,因此它甚至不会为我们编译,更不用说了给我们一个输出!
Run it, and find out.
We can't - we don't have yourswap2
function, so it won't even compile for us, much less give us an output!
这篇关于上述计划的产出是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文