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

Discussion

What will be the value of d in the following program?    

int main()
    {
        int a = 10, b = 5, c = 5;
        int d;
        d = b + c == a;
        printf("%d", d);
    }

 

  • A.Syntax error
  • B.1
  • C.5
  • D.10

Answer: B

Correct answer: 1

== binds tighter than =, so the statement is d = ((b + c) == a). Since \(5 + 5 = 10\) equals a, the comparison is true and yields 1. Had = bound tighter the code would not even compile, since d = b + c is not something you can compare in that position.

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

Post your comment

Please log in or register to post a comment.