Discussion
Which of the following statement is correct about the code snippet given below?
#include <stdio.h>
int main()
{
int a = 10, b = 2, c;
a = !( c = c == c) && ++b;
c += ( a + b--);
printf( " %d %d %d", b, c, a);
return 0;
}
Answer: A
Correct answer: The program will print the output 1 3 0
Take the statements in order.
a = !(c = c == c) && ++b;-c == cis 1, socbecomes 1 and!1is 0. The&&short-circuits, so++bnever runs andbstays 2.abecomes 0.c += (a + b--);-a + bis \(0 + 2 = 2\), socbecomes \(1 + 2 = 3\), and the post-decrement leavesbat 1.
Printing b, c, a gives 1 3 0.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development