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

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);
    }

 

  • A.5  1
  • B.0  3
  • C.5  3
  • D.1  1

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.