Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

#include <stdio.h>
#define MIN(x, y) (x<y) ? x : y

int main()
{
    int x=3, y=4, z;
    z = MIN(x, y);
    if(z > 0)
        printf("%d\n", z);
    return 0;
}

 

  • A.3
  • B.4
  • C.No output

Answer: A

Correct answer: 3

MIN(x, y) expands to (x<y) ? x : y, so with \(x = 3\) and \(y = 4\) the condition holds and z gets 3. Since 3 is greater than 0, the if succeeds and the value is printed. (The macro has no outer parentheses, so it would misbehave inside a larger expression - but the assignment here is safe.)

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.