"Nothing in life is to be feared, it is only to be understood."
- Marie Curie
What will be the output of the program?
k = func1(k=func1(k=func1(k)));
int func1(int k)
Answer: Option A
Step 1: int k=35; The variable k is declared as an integer type and initialized to 35.
Step 2: k = func1(k=func1(k=func1(k))); The func1(k) increement the value of k by 1 and return it. Here the func1(k) is called 3 times. Hence it increements value of k = 35 to 38. The result is stored in the variable k = 38.
Step 3: printf("k=%d\n", k); It prints the value of variable k "38".
There is a postfix increment operator so the value should not increase before going to the caller function so there should not be any increment in value.
(Fri, Dec 2, 2011 11:19:22 PM)
@priya: No you are wrong.If the return statement would be like return(k++),then answer should be 35.But here,in this case,first k is post incremented and in next step return(k++) it actually incremented and return incremented value.