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

Discussion

What is the output of this C code?    

int main()
    {
        int c = 2 ^ 3;
        printf("%d\n", c);
    }

 

  • A.1
  • B.8
  • C.9

Answer: A

Correct answer: 1

^ is bitwise exclusive OR, not exponentiation - a common trap for anyone coming from a language where ^ means “to the power of”:

\[ 2 = 010_2, \quad 3 = 011_2, \quad 010 \oplus 011 = 001_2 = 1 \]

So c is 1, not 8.

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

Post your comment

Please log in or register to post a comment.