Fill in the final values of x y and z just before main retur
Fill in the final values of x, y, and z just before main returns int main() {int x = 1; int y = 2; int z = 3; int *x_ptr = &x; ++(*x_ptr); z = *x_ptr; ++(*x_ptr); int *ptr = &y; *ptr = *x_ptr + z;}
Solution
The answer is : x = 3, y = 5 and z = 2.
Step - by - step solution is as follows:
So, x = 3, y = 2, z = 3.
z is assigned the value of the address hold by x_ptr i.e. value of x which is 2. Then same as above, one more time value of x is increased.
So, x = 3, y = 2, z = 2
ptr pointer points to memory location of where the value of variable y is stored. So, *ptr means y value. And here, last statement measns : x + z = y. So, 3 + 2 = 5.
So, final answer is X = 3, y = 5 and z = 2.
If there is any query, please comment. I will surely resolve that query. Thank you. :)
