ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned a = 7;
printf("%u", a / 2 * 2);
}- A. 7
- B. 1
- C. 6
- D. 3
Correct answer: C. 6
/ and * have equal precedence and group left to right, so 7 / 2 = 3 (truncated), then 3 * 2 = 6. 7 assumes the / 2 and * 2 cancel, 1 groups it as 7 / (2 * 2), and 3 stops after the division.
More C Programming questions
- What is printed? c #include <stdio.h> int f(int n) { static int memo[10]; if (n < 2) return n; if (memo[n]) return memo[n]; return memo[n]…
- What is printed? c #include <stdio.h> int main(void) { printf("%c", 'a' + ('z' - 'a') / 2); }
- How many trailing one bits does 0x1F3 have? Compute with this program. c #include <stdio.h> int main(void) { unsigned x = 0x1F3; int c =…
- What is printed? c #include <stdio.h> int main(void) { unsigned long long p = 0xFFFFu 0xFFFFu; printf("%llu", p); }
- What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f. c #include <stdio.h> void f(char s[]) {…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 2 3 + 4 % 3 == 0 ? 1 : 2); }