尤其是c=a+b++,int fun(int a){ int c;static int b=3;c=a+b++;return c;}void main(void){ int x=2 ,y;y=fun(x);printf("y=%d",y);y=fun(x+3);printf("y=%d",y);}

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 02:10:01
尤其是c=a+b++,intfun(inta){intc;staticintb=3;c=a+b++;returnc;}voidmain(void){intx=2,y;y=fun(x);printf("

尤其是c=a+b++,int fun(int a){ int c;static int b=3;c=a+b++;return c;}void main(void){ int x=2 ,y;y=fun(x);printf("y=%d",y);y=fun(x+3);printf("y=%d",y);}
尤其是c=a+b++,
int fun(int a)
{ int c;
static int b=3;
c=a+b++;
return c;
}
void main(void)
{ int x=2 ,y;
y=fun(x);printf("y=%d",y);
y=fun(x+3);printf("y=%d",y);
}

尤其是c=a+b++,int fun(int a){ int c;static int b=3;c=a+b++;return c;}void main(void){ int x=2 ,y;y=fun(x);printf("y=%d",y);y=fun(x+3);printf("y=%d",y);}
static int b=3;这句编译时处理,可认为第一次调用fun时才执行,且b存放在静态存储区,fun函数调用完后b的内存不被释放.也就是说,第一次调用fun时b初始化为3,此后在调用fun时,static int b=3;这一句已经不存在了,因为它是编译时处理的,此时的b值应该使用之前的存储值,因为b的内存直到整个程序结束后才释放.
所以:
y=fun(x);printf("y=%d",y);
首次调用fun,b=3;c=a+b++;执行后,b等于4,c等于5(因为b++的值为3,后缀++)
y=5
y=fun(x+3);printf("y=%d",y);
第二次调用fun,b=4;
c=a+b++;执行后,b等于5,c等于9
y=9
即最终打印:
y=5y=9

开始,
1,x=2;
2,调用fun(x):
{
a=2;
b=3;

接下来是“c=a+b++”:
"b++"表示b在当前表达式结束后加1;
即上式相当于:
c=a+b;
...

全部展开

开始,
1,x=2;
2,调用fun(x):
{
a=2;
b=3;

接下来是“c=a+b++”:
"b++"表示b在当前表达式结束后加1;
即上式相当于:
c=a+b;
b=b+1;
所以最终返回的是5;
此时b=4;
}
3,输出“y=5”
4,调用fun(x+3),
因为b的类型为static int ,所以此时不在对b进行初始化,即b=4,所以返回9;
5,输出“y=9”

收起

尤其是c=a+b++,int fun(int a){ int c;static int b=3;c=a+b++;return c;}void main(void){ int x=2 ,y;y=fun(x);printf(y=%d,y);y=fun(x+3);printf(y=%d,y);} C语言 这个fun函数哪里错了?#include #include #include void fun(char *a,int b[]){int i;for(i=0;i void fun(int a,int b) { int t; t=a;a=b;b=t; } main()void fun(int a,int b){ int t; t=a;a=b;b=t; } main() { int c[10]={1,2,3,4,5,6,7,8,9,0}.i; for(i=0;i #include void fun(int a, int b) { int t; t=a; a=b; b=t;main() { int c[10]={1,2,3,4,5,6,7,8,9,0), i; for (i=0; i #include void fun(int a,int b) {int t; t=a;a=b;b=t; } main() {int c[6]={1,2,3,4,5,6},i;for(i=0;i #include int inc(int a){ return(++a); }int multi(int*a,int*b,int*c){ return(*c=*a**b); }typedef int(FUNC1)(int in);typedef int(FUNC2) (int*,int*,int*);void show(FUNC2 fun,int arg1,int*arg2){FUNC1 p=&inc;int temp =p(arg1);fun(&temp,&arg1,arg2);printf( #include stdio.h void fun(int a,int b) { int t; t=a,a=b,b=t; } main() { int c[10]={1,2,3,4,5,6,7#include stdio.hvoid fun(int a,int b){int t;t=a,a=b,b=t;}main(){int c[10]={1,2,3,4,5,6,7,8,9,0},i;for(i=0;i 数组a与数组b对应元素相加放入c数组中,输入c数组#includestdio.hvoid fun(int*f,int*p,int*q){for(int i=0;i c语言这段程序看不懂int fun(int a,int b,int c){ int t; t=(a>b)?(b>c?b:(a>c?c:a)):((a>c)?a:((b>c)?c:b)); return t; } void fun(int *a,int *b) { int *c; c=a;a=b;b=c; } main() { int x=3,y=5,*p=&x,*q=&y; fun(p,q);...void fun(int *a,int *b){ int *c; c=a;a=b;b=c;}main(){ int x=3,y=5,*p=&x,*q=&y; fun(p,q); printf(%d,%d,,*p,*q); fun(&x,&y); prin%d,%d ,*p,*q);}两 #include int inc(int a) { return(++a); } int multi(int*a,int*b,int*c) { return(*c=*a**b); }typedef int(FUNC1)(int in);  typedef int(FUNC2) (int*,int*,int*);  void show(FUNC2 fun,int arg1,int*arg2)  {  INCp=&inc;  int temp =p(arg1) void fun(int *a,int n) { int i,j,k,t; for(i=0;i #include void fun(int a[],int n) { int i,t; for(i=0;i 下列各个成员函数中,纯虚函数是( ) A.void fun(int)=0 B.virtual void fun(int) C.virtual void fun #include int b=2; int fun(int*k) { b=*k+b;return(b);} main() {int a[10]={1,2,3,4,5,6,7,8}#include int b=2; int fun(int*k) { b=*k+b;return(b);} main() {int a[10]={1,2,3,4,5,6,7,8},i;for(i=2;i 3、以下正确的函数定义是( ).A.double fun(int x,int y); {int z; z=x+y; return z;}3、以下正确的函数定义是( ).A.double fun(int x,int y); {int z; z=x+y; return z;}B.fun(int x,y) {int z; return z;}C.double fun( 以下函数的正确定义形式是( )A double fun(int x,int y) B.double fun(int x;int y) C.double fun(int x,int y); D.double fun(int x,y); 8、以下正确的函数定义是A)double fun(int x ,int y) B)double fun(int x ; int y)C)double fun(int x ,int y) ; D)double fun(int x,y)