#include<stdio.h>
#define FNC(x, y) ((x) > (y)) ? (* * y) : (y - x);
int main() {
int p = 7, 9 = 6, r = 4;
r += FNC (++p, q++);
printf("%d%d %d", p, q, r);
return 0;
0}
Answers
Answered by
2
Answer:
67
Explanation:
Here ,there is small correction in question."#define FNC(x, y) ((x) > (y)) ? (* * y) : (y - x);"==>This statement should actually be#define FNC(x, y) ((x) > (y)) ? (x * y) : (y - x);
When FNC(++p,q++) is called===>FNC(++p>q++)?(++p*q++):(q++-++p)
p=7 q=6 8>6 9*7
p=9 q=7
r=4+63=67
Answered by
0
Answer:
The output of the given code is 9 8 67.
Explanation:
- A function FNC is defined at the start of the program. This function takes two arguments.
- The FNC function compares which of the two arguments is greater. If the first argument is greater than the second, the first expression after the question mark is executed.
- If the second argument is greater than the first, the second expression after the question mark (or the expression after the colon) is executed.
- The corresponding result is passed back to the main function.
- In the main function, three variables p, q, and r are initialized to values 7, 6, and 4 respectively.
- Then the FNC function is called with arguments as ++p and q++. This means that the value of p is incremented by 1 before it is passed as a function argument and the value of q is incremented by 1 after the function is run.
- So, the function call may look like this r+=FNC ( 8, 6)
- The function compares the two arguments ++p (8) and q++ (6) and the value of q is incremented by 1 to q=7. Since ++p is greater than q++, the first expression after the question mark is executed.
- Here too, ++p causes the value of p to be incremented by 1 to 9 before the execution of the statement, and the value of q++ is incremented after the execution.
- (++p * q++) will be (9 * 7) which results in 63. The value is q is incremented by 1 to 8.
- The result of the function execution is then passed back to the main function.
- In the main function, this result is added to the value of r which was initialized to 4. So, the new value of r becomes r=4+63=67.
- The final values of p, q, and r are printed and the program is terminated.
Therefore, the program prints the final values of the variables p, q, and r which are 9, 8, and 67.
#SPJ3
Similar questions