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

What will be the output of the following C code?
#include<stdio.h>
void main() {
  int arr[5] = {10,20,30,40,50};
  int *p = (int*)(&arr + 1);
  printf("%d %d", *(arr+1), *(p-1));
}

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

Show answer & explanation

Correct answer: B. 20 50

Explanation

*(arr + 1) = arr[1] = 20. &arr + 1 points just past the whole array, so p − 1 points to the last element, 50.

More Programming Languages and Computer Graphics questions