ProgrammingHardAccenture · Capgemini
Assume ASCII. What is printed?
Assume ASCII. What is printed?
char s[] = "aB3";
for (char *p = s; *p; p++)
*p ^= 32;
printf("%d %d %d", s[0], s[1], s[2]);- A. 97 66 51
- B. 65 98 19
- C. 65 98 51
- D. 65 98 83
Correct answer: B. 65 98 19
XOR with 32 flips bit 5. For letters that swaps case: 'a' (97) → 65, 'B' (66) → 98. It is not a case operation, though: it flips the digit '3' (51) too, giving 19. '51' assumes digits are left alone; '83' adds 32 instead of flipping the bit.
More C Programming questions
- What is printed? c void f(int p, int n) { if (n == 0) return; p += n; f(p, n - 1); p = 2; } int main(void) { int x = 0; f(&x, 3)…
- On an LP64 system (8-byte pointers), what is printed? c printf("%zu %zu", sizeof("abc"), sizeof("abc" + 1));
- On an LP64 system (8-byte pointers), what is printed? c char a[] = "cat", b = "cat"; printf("%d %d", strcmp(a, b) == 0, sizeof(a) ==…
- What is printed? c struct P { int x; int y; }; struct P a[3] = {{1, 2}, {3, 4}, {5, 6}}; struct P p = a; int r1 = (p + 2)->x; int r2 =…
- With a C99 (or later) compiler, what is printed? c int ds(int n) { return n == 0 ? 0 : n % 10 + ds(n / 10); } int main(void) {…
- What is printed? c int f(unsigned x) { int c = 0; while (x) { c += x & 1; x >>= 2; } return c; } int main(void) { printf("%d", f(0xFF) +…