作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 22:57:17
#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;
#include sub1(char a,char b) {char c;c=a;a=b;b=c;} sub2(char
你要问的是这个吧...我也在做这个
# 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'.