Discussion
What is the output of this C code?
int main()
{
int a = 10, b = 5, c = 3;
b != !a;
c = !!a;
printf("%d\t%d", b, c);
}
Answer: A
Correct answer: 5 1
b != !a; is an expression statement whose value is computed and thrown away - it does not assign anything, so b remains 5. c = !!a applies logical NOT twice: !10 is 0 and !0 is 1, so the double negation reduces any non-zero value to 1. That idiom is the usual way of normalising a value to 0 or 1.
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