ProgrammingHardTCS NQT · Infosys
int a = 1 ? 2 : 3 ? 4 : 5; What is a?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: D. 2
The conditional operator groups to the right, so the expression is 1 ? 2 : (3 ? 4 : 5). The condition 1 is true, which selects 2.
More C Programming questions
- char p = "xyz"; char a[] = "xyz"; a[0] = 'Q'; printf("%s", a); What is printed?
- char s[4] = "abc"; What is sizeof s?
- Ackermann-style recursion: A(0,n) = n + 1 and A(m,0) = A(m-1,1), with A(m,n) = A(m-1, A(m,n-1)). What is A(1,5)?
- How many ordered ways are there to write 10 as a sum of parts equal to 1, 3 or 4, where the order of the parts matters?
- int arr[10]; What is sizeof(int[10]) / sizeof(int)?
- What does printf("%d", 10 / 3 3 == 10) print?