ProgrammingHardTCS NQT · Product company OA
What is printed?
What is printed?
int x = 3, y = 1;
printf("%d %d", !x == y, !(x == y));- A. 1 0
- B. 0 0
- C. 1 1
- D. 0 1
Correct answer: D. 0 1
Unary ! binds tighter than ==, so !x == y means (!x) == y = 0 == 1 = 0. !(x == y) negates 3 == 1, which is false, giving 1. Moving the ! changes what it applies to.
More C Programming questions
- For ints a and b with b != 0 and no overflow, which statement is always true in C99 and later?
- Why should a header file shared by several .c files not contain the line int counter = 0;?
- With 4-byte int, what is printed? c int n = 0; int f(void) { n++; return 1; } int main(void) { sizet s = sizeof(f()); printf("%zu %d", s…
- What is printed? c int n = 3, s = 0; while (n--) s += n; printf("%d %d", s, n);
- Assume ASCII. What is printed? c int cmp(const void a, const void b) { return strcmp((const char )a, (const char )b); } int main(void) {…
- What is printed? c int g[3][3] = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}}; int mp(int r, int c) { if (r == 0 && c == 0) return g[0][0]; if (r < 0…