ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
char *w[] = {"red", "green", "blue"};
char **p = w + 1;
printf("%c %s %c %zu", **p, *(p + 1) + 2, *(*(p - 1) + 1),
strlen(p[1]) - strlen(*w));- A. g ue r 1
- B. g ue e 1
- C. r ue e 1
- D. g lue e 1
Correct answer: B. g ue e 1
p points at w[1] ("green"), so **p is 'g'. *(p + 1) is w[2] = "blue"; adding 2 skips two characters, printing "ue". *(p − 1) is w[0] = "red" and +1 selects 'e'. strlen("blue") − strlen("red") is 1 (both are size_t, and 4 − 3 does not wrap).
More C Programming questions
- What is printed? c struct { unsigned a : 3; unsigned b : 5; } f = {0, 0}; f.a = 9; f.b = 33; printf("%u %u ", f.a, f.b); f.a += 7; f.b =…
- What is printed? c / 32-bit unsigned int / unsigned np2(unsigned v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >>…
- What is printed? c / 8-bit unsigned char, 32-bit int / unsigned char c = 0x80; printf("%d %d %d %d", c << 1, (unsigned char)(c << 1), ~c…
- What is printed? c char s[] = "a,b,,c"; int n = 0; for (char t = strtok(s, ","); t; t = strtok(NULL, ",")) n++; printf("%d %zu %c", n…
- What is printed? c char s[] = "Hello"; s[0] = 'J'; s[4] = '0'; printf("%s %zu", s, sizeof(s));
- What is printed? c int i = 5; printf("%d ", i++); printf("%d", ++i);