All mock tests are FREE till 31 December — register to save your progress

Find the output of the following code:
#include<stdio.h>
void main() {
  int arr[] = {1, 2, 3, 4, 5};
  int *p = arr;
  printf("%d", *p++);
  printf("%d", *(p+1));
}

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. 1, 3

Explanation

*p++ prints arr[0] = 1 and then advances p to arr[1]. *(p + 1) is arr[2] = 3. Output: 1 and 3.

More Programming Languages and Computer Graphics questions