The following program fragment int k=-7; printf("%d", 0 < !k);

  • 0 replies
  • 900 views
*

Offline mechanic

  • *****
  • 2513
    • View Profile
    • Engineering Forum
Question: The following program fragment

int k=-7;
printf("%d", 0 < !k);


Options are:

A. prints 0
B. prints a non-zero value
C. is illegal
D. prints an unpredictable value

Correct answer is:

A. Prints 0


Explanation:

k = - 7, so if 'k' is used as a boolean variable, it will be treated as a true condition. so, !k will be false i.e. 0. so 0 <? !k is actually 0 < 0. which is false. so. 0 will be printed.
« Last Edit: March 08, 2017, 08:44:44 AM by mechanic »