void funct(int i = 10, int j = 20)
int *ptr = &i;
int main(int argc, char* argv)
Ans: 20 and 30
This is a C++ specific question. We have taken a local pointer of integer and assigned the address of first argument i.e. the address of i. Arguments are pushed in a C function sequentially from right to left. Stack pointer decrements by sizeof(int) with every argument push. Thus the first argument points at the lowest address and the last argument points at the highest address.
return address of funct()
code address of next to call
Now when we increment the pointer it will point to the next argument i.e. the address of j. So, value of the pointer is the value of j itself. For the first function call, the value is the default value of j i.e. 20. But for the next function call, we have given the value 30 explicitly. Thus the value will be 30.
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.