ProgrammingHardProduct company OA
What is printed?
What is printed?
printf("%d", 5["abcdef"] - 'a');- A. Compilation error
- B. 5
- C. 102
- D. 6
Correct answer: B. 5
E1[E2] is defined as *(E1 + E2), so 5["abcdef"] is the same as "abcdef"[5], the character 'f'. 'f' − 'a' = 5 because lower-case letters are consecutive in ASCII. 102 is the code of 'f' itself.
More C Programming questions
- What is printed? c const char s = ""; int n = 0; for (int i = 0; i < strlen(s) - 1; i++) { n++; if (n > 5) break; } printf("%d", n);
- What is printed? c int pm(int b, int e, int m) { if (e == 0) return 1 % m; int h = pm(b, e / 2, m); h = h h % m; return e % 2 ? h b % m…
- What is printed? c #define STR(x) #x printf("%zu", strlen(STR( a + b )));
- What is printed? c char g[3][4] = {"abc", "def", "ghi"}; for (int j = 0; j < 3; j++) putchar(g[2 - j][j]);
- A file report.txt already exists and holds data. What does fopen("report.txt", "w") do?
- The user types hello and presses Enter. After char buf[8]; fgets(buf, sizeof buf, stdin);, what does buf hold?