ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
char s[] = "abcdef";
char *p = s;
int n = 0;
while (*p && p - s < 4)
n += *p++ - 'a';
printf("%d %c", n, *p);
}- A. 10 e
- B. 6 d
- C. 10 f
- D. 6 e
Correct answer: D. 6 e
The loop adds the offsets 0, 1, 2 and 3 from 'a' and stops when p - s reaches 4, leaving p on 'e'. The sum is 6, and the trap value 10 comes from adding one extra element.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { const int x = (int const )a; const int y =…
- What is printed? c #include <stdio.h> int main(void) { int m[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) m[i][j] = i 3…
- How many times is disk 3 moved in this recursive Towers of Hanoi with 5 disks? Compute the program output. c #include <stdio.h> int cnt =…
- How many integers n with 1 <= n <= 64 satisfy both (n & (n - 1)) == 0 and (n & 0x55555555u) != 0? Compute with this program. c #include…
- What is printed? c #include <stdio.h> int main(void) { int a[5]; int p = a + 4, q = a + 1; printf("%ld", (long)(p - q) (long)sizeof p); }
- What is printed? Assume int is 32 bits and integer division truncates toward zero. c #include <stdio.h> int main(void) { int v[] = {-7…