ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
int arr[] = {10, 20, 30, 40};
int *p = arr;
p += 2;
printf("%d", *p);- A. 40
- B. 30
- C. 12
- D. 20
Correct answer: B. 30
Pointer arithmetic moves in units of the pointed-to type: p += 2 moves two ints ahead, to arr[2], which is 30. It does not add 2 bytes or 2 to the value.
More C Programming questions
- What does f(4096) return? c int f(int n) { if (n == 0) return 0; return n % 10 + f(n / 10); }
- What is printed? c printf("%d %d %d", 12 & 10, 12 | 10, 12 ^ 10);
- What is printed? c #define SQUARE(x) x x printf("%d", SQUARE(2 + 3));
- What is printed when count() is called three times in a row? c void count(void) { static int c = 0; c++; printf("%d ", c); }
- What is printed? c int a[5] = {1, 2}; printf("%d", a[3]);
- What is printed? c int x = 5; printf("%d", x > 3 ? x < 10 ? 1 : 2 : 3);