Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Friday, 16 July 2021

Interview Hack#48 Answer

 What will be output if you will execute following c code?

Captionless Image

  1. 5 5
  2. 3 5
  3. 4 5
  4. 5 4
  5. Error


Correct answer
Explanation:
x = ++a, ++a, a++
x = 3, ++a, a++ // a = 2 + 1
x = 3, ++a, a++ // = operator has higher precedence than comma operator
x = 3, ++a, a++ // a = 3 + 1
x = 3, 4, a++
x = 3, 4, 4 // a = 4 + 1
x = 3 // a = 5

0 comments:

Post a Comment