#include sub1(char a,char b) {char c;c=a;a=b;b=c;} sub2(char

xwt0272022-10-04 11:39:541条回答

#include sub1(char a,char b) {char c;c=a;a=b;b=c;} sub2(char *a,char b) {char c;c=*a;*a=b;

已提交,审核后显示!提交回复

共1条回复
taotao83tly 共回答了16个问题 | 采纳率75%
你要问的是这个吧...我也在做这个
# include "stdio.h"
void sub1(char a,char b)
{ char c; c=a; a=b; b=c; }
void sub2(char *a,char b)
{ char c; c=*a; *a=b; b=c; }
void sub3(char *a,char *b)
{ char c; c=*a; *a=*b; *b=c; }
void main()
{ char a,b; a='A'; b='B';
sub3(&a,&b); putchar(a); putchar(b);
sub2(&a,b); putchar(a); putchar(b);
sub1(a,b); putchar(a); putchar(b);
}
答案是BAAAAA
sub3(&a,&b);a,b交换值,得a = 'B',b = 'A';
sub2(&a,b);b的值再赋给a,得a = 'A',b作为形参,值不变,b = 'A'
sub1(a,b);a,b都为形参,a,b的值都不变,a= 'A',b = 'A'.
1年前

相关推荐

大家在问