ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int a[] = {5, 10, 15};
int *p = a;
int x = *p++;
int y = (*p)++;
int z = *++p;
printf("%d %d %d %d", x, y, z, a[1]);- A. 5 11 15 11
- B. 6 10 15 10
- C. 5 10 11 11
- D. 5 10 15 11
Correct answer: D. 5 10 15 11
*p++ reads a[0] = 5 and moves p to a[1]. (*p)++ yields 10 and then makes a[1] 11, with p unchanged. *++p moves p to a[2] and reads 15. So 5 10 15 and a[1] = 11.
More C Programming questions
- With 32-bit unsigned int, what is printed? c unsigned int x = 0; x--; printf("%u %d", x, x > 0);
- With ASCII and 4-byte int, what is printed? c char c = 'A'; c = c + 32; printf("%c %zu", c, sizeof(c + 1));
- What is printed? c char s[] = "abcdef"; char p = s, q = s + strlen(s) - 1; while (p < q) p++ = q--; printf("%s", s);
- What is printed? c struct A { int a[2]; }; struct B { int p; }; int v = 5; struct A x = {{1, 2}}, y; struct B m = {&v}, n; y = x; n = m…
- With 4-byte int and 8-byte double aligned on 8 bytes, what is sizeof(union U)? c union U { int i; double d; char c[10]; };
- What is printed? c int nextid(void) { static int id = 0; return ++id; } int main(void) { int a = nextid(), b = nextid(), c = nextid()…