ProgrammingEasyWipro · Capgemini pattern
What is printed?
What is printed?
printf("%c %d %d", 'A' + 2, 'A' + 2, 'z' - 'a');- A. C 67 26
- B. C 67 25
- C. B 66 25
- D. 67 C 25
Correct answer: B. C 67 25
Characters are small integers: 'A' is 65, so 'A' + 2 is 67, printed as 'C' with %c and 67 with %d. Letters are contiguous in ASCII, so 'z' − 'a' = 25 (not 26).
More C Programming questions
- What is printed? c unsigned char a = 250, b = 10, z = 0; int s = a + b; unsigned char t = a + b; z--; printf("%d %d %d", t, z, s);
- What is printed? c int x = 6; printf("%d %d", x & 2 == 2, (x & 2) == 2);
- What is printed? c int a = (1, 2, 3); int b = 5; b = (b + 1, b 2); printf("%d %d", a, b);
- What is printed? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 2); } } int main(void) { f(3); }
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d %d", ((a + 1) + 2), (a[1] + 1), a + 1);
- What is printed? c char s[] = "hello"; char p = s; printf("%zu %zu %zu", strlen(s), sizeof(s), sizeof(p)); / 64-bit system /