ProgrammingHardTCS NQT · Infosys
int x = 0; if (x = 5) printf("y"); else printf("n"); What is printed?
- A. nothing
- B. y
- C. compile error
- D. undefined
Correct answer: B. y
x = 5 assigns 5 to x and yields 5, which is nonzero, so the condition is true. The program prints y, a classic slip for == is still valid C.
More C Programming questions
- Which expression clears the lowest three bits of an unsigned char x?
- uint32t x = 0u; x -= 1; x = x / 2 + 1; What is x?
- int a[5]; int p = &a[4]; printf("%td", p - &a[0]); What is printed?
- What does printf("%d", '7' - '0' == 7) print?
- Reversing the list 1 -> 2 -> 3 -> 4 -> 5 in place with the usual three-pointer loop, what are head->v and head->next->v afterwards?
- In a list 1 -> 2 -> 3 -> 4 -> 2 where the last node points back to the node holding 2, Floyd's method runs slow = slow->next and fast =…