ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
char w[][6] = {"red", "green", "blue"};
printf("%zu %zu %zu", sizeof(w), sizeof(w[1]), strlen(w[1]));- A. 18 6 6
- B. 24 8 5
- C. 18 6 5
- D. 15 6 5
Correct answer: C. 18 6 5
w is a real 2-D array of 3 rows of 6 chars, so sizeof(w) = 18 and each row is 6 bytes, whatever string it holds. strlen("green") is 5. '24 8 5' would be an array of 3 pointers on a 64-bit machine, which this is not.
More C Programming questions
- What is printed? c int m = 0; long p(long b, int e) { if (e == 0) return 1; long h = p(b, e / 2); m++; if (e % 2) { m++; return h h b; }…
- What is printed? c enum Flag { RED = 1, GREEN = RED << 1, BLUE = GREEN << 1, ALL = RED | GREEN | BLUE }; printf("%d %d", ALL, ALL & ~GREEN);
- 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);