ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
char *s = "hello";
printf("%c %c %c", s[1], 4[s], *("abc" + 2));- A. h l c
- B. e o c
- C. e o b
- D. e l c
Correct answer: B. e o c
s[1] is 'e'. Because a[i] is defined as *(a + i), 4[s] means *(4 + s) = s[4] = 'o'. A string literal decays to a pointer, so "abc" + 2 points to 'c'.
More C Programming questions
- What is printed? c int x = 10; int p = &x; int q = &p; q = 20; p += 5; printf("%d", x);
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int i = 3; int r = MAX(i++, 2); printf("%d %d", r, i);
- What is printed? c unsigned int i; int count = 0; for (i = 3; i >= 0; i--) { if (++count == 5) break; } printf("%d %u", count, i); /…
- What is printed? c printf("%d %d %d %d", -17 / 5, -17 % 5, 17 / -5, 17 % -5);
- What is printed? c int i = 5; sizet s = sizeof(i++); printf("%zu %d", s, i); / 4-byte int /
- What is printed? c char names[] = {"Ann", "Bob", "Cy"}; printf("%c %s %zu", names[1][0], names[2], strlen(names[0]));