ProgrammingModerateAccenture · Capgemini
What is printed?
What is printed?
enum Flag { RED = 1, GREEN = RED << 1, BLUE = GREEN << 1, ALL = RED | GREEN | BLUE };
printf("%d %d", ALL, ALL & ~GREEN);- A. 7 5
- B. 3 1
- C. 6 4
- D. 7 6
Correct answer: A. 7 5
Enumerators can be built from earlier ones: RED = 1, GREEN = 2, BLUE = 4, ALL = 7. ALL & ~GREEN clears bit 1: 7 & …11111101 = 5. '7 6' clears bit 0 instead.
More C Programming questions
- What is printed? c void rev(char s, int i, int j) { if (i >= j) return; char t = s[i]; s[i] = s[j]; s[j] = t; rev(s, i + 2, j - 2); } int…
- Why are multi-statement macros usually written as #define M(x) do { ... } while (0)?
- What is printed? c #define INC(x) x++; x++ int a = 0, b = 0; if (a > 5) INC(b); printf("%d", b);
- What is printed? c int x = 7 / 2 2.0; double y = 7 / 2.0 2; printf("%d %.1f", x, y);
- What is printed? c void move(int pp) { (pp)++; pp += 10; } int main(void) { int a[] = {1, 2, 3}; int p = a; move(&p); move(&p); printf("%d…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xABCD; printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));