Consider the following C program:
int fun(int p, int*q)
{
int n;
*q+=5;
n=*q;
p=p+n;
return(p+n);
}
main()
{
int i=0, *p, y;
p=&i;
y=fun(i, p);
printf("%d", y);
}
The output of the above program is ________.
- 5
- 10
- 15
-----------------------------------------------------------------------------------------------------------------------------------------------
here i is sent by value and address of i is sent in p
in func()--
first statment ,*q+=5 makes *q =5 which implies that i has become 5 now.so does p also become 5 here?i dun think so,because p is the copy of 'i'.it should not be changed to 5,it should stay 0 only.
now next statement p=p+n means p=0 +5=5
now,return statement (p+n) returns (5+5) =10
am i correct or not??