下面程序段运行后的输出结果是【 】 (假设程序运行时输入5,3回车)
int a, b;
void swap
{
int t;
t=a; a=b; b=t;
}
main()
{
scanf("%d,%d", &a, &b);
swap;
printf ("a=%d,b=%d
",a,b);
}
int a, b;
void swap
{
int t;
t=a; a=b; b=t;
}
main()
{
scanf("%d,%d", &a, &b);
swap;
printf ("a=%d,b=%d
",a,b);
}
举一反三
- 中国大学MOOC: 下列程序调用swap函数交换a和b的值,并输出交换后的a和b的值。程序的输出结果是:After swap 5, 3。void swap( int *p, int *q ){ int t; t=*p; *p=*q; *q=t;}void main( ){ int a=3, b=5; swap(______________________) ; printf(After swap %d, %d, a, b);}
- 执行以下程序后,输出结果是__________。 #include Void swap(int *x,int *y) {int t; t=*x,*x=*y,*y=t; } Void main( ) {int a=12,b=24; Swap(&a,&b); Printf(“%d,%d”,a,b); }
- void swap(int, int); void main(){int a=3,b=5; printf(“a=%d, b=%d”,a,b); swap(a, b); printf(“a=%d, b=%d”,a,b); } void swap(int x, int*y); {int temp = x; x=y; y=temp;} 这段程序计算结果是
- 写出下列程序运行结果 #include “stdio.h” void swap(int *px , int *py ); void main() { int a,b; a=5; b=10; printf(“ before swap a=%d, b=%d ”,a,b); swap(&a,&b); printf(“after swap a=%d, b=%d ”,a,b); } voidswap(int *px , int *py ) { int temp; temp=*px; *px=* py; *py=temp; printf(“ in swap x=%d,y=%d ”,*px, *py); }
- 下面程序应能对两个整型变量的值进行交换。以下正确的说法是__________。 int main() { int a=10,b=20; printf("%d,%d",a,b); swap(&a,&b); printf("%d,%d",a,b); return 0; } void swap(int p,int q) { int t; t=p;p=q;q=t; }