+ 3
Why the output of b is 16 not 18
#include <stdio.h> int main() { int a[5],i,b=16; for(i=0;i<5;i++) a[i]=2*i; f(a,b); for(i=0;i<5;i++) printf("\n%d",a[i]); printf("\nb=%d",b); return 0; } f(int *x,int y) { int i; for(i=0;i<5;i++) *(x+i)+=2; y+=2; printf("\ny=%d",y); }
1 Réponse
0
You initialize b to 16 and never change its value.
Remember the difference between int *x and int x when using them as arguments for functions. int x does not change that variable, in this case, b.
Does this make sense?