ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
printf("%d", 2 + 3 << 1 & 7);- A. 9
- B. 2
- C. 8
- D. 10
Correct answer: B. 2
Precedence order is + then << then &: ((2 + 3) << 1) & 7 = (5 << 1) & 7 = 10 & 7 = 1010 & 0111 = 2. Grouping 3 << 1 & 7 first gives 2 + 6 = 8.
More C Programming questions
- How many of these are correct in C? (i) A global variable without an initialiser starts as 0. (ii) A static local variable is initialised…
- What is f in the declaration int (f)(int); ?
- What is printed? c int a[] = {5, 10, 15}; int p = a; int x = p++; int y = (p)++; int z = ++p; printf("%d %d %d %d", x, y, z, a[1]);
- With 32-bit unsigned int, what is printed? c unsigned int x = 0; x--; printf("%u %d", x, x > 0);
- With ASCII and 4-byte int, what is printed? c char c = 'A'; c = c + 32; printf("%c %zu", c, sizeof(c + 1));
- What is printed? c char s[] = "abcdef"; char p = s, q = s + strlen(s) - 1; while (p < q) p++ = q--; printf("%s", s);