ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[3] = {1, 2, 3};
int *p = a;
printf("%d ", *p++);
printf("%d ", *p);
}- A. 1 2
- B. 2 2
- C. 1 1
- D. 2 3
Correct answer: A. 1 2
Postfix ++ binds tighter than unary *, so *p++ means *(p++): it dereferences p first (giving a[0]=1) and only afterwards advances p to a[1]. The second printf then reads the now-current a[1]=2.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[4] = {10, 20, 30, 40}; int p = a, end = a + 4; int sum = 0; while (p != end)…
- Assume a 4-byte int. What is printed? c #include <stdio.h> int main(void) { int a[2][3]; int (p)[3] = a; p++; printf("%ld", (long)p…
- What is printed? Assume sizeof(int) == 4. c int a[4] = {1, 2, 3, 4}; int p = a; printf("%d ", (p++)); printf("%d ", (++p)); printf("%d"…
- What is printed? c int a, b, c; a = b = c = 5; printf("%d %d %d", a, b, c);
- file1.c: c static int secret = 7; int getSecret(void) { return secret; } file2.c: c int getSecret(void); int main(void) { printf("%d"…
- What is printed? c int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; int p = (int )a; printf("%d %d %d", (p + 5), ((a + 1) + 2), (a[2] +…