Question discussion

What will be the output of the following code?

359427Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following code?
#include <stdio.h>
int main() {
    int arr[] = {1, 2, 3, 4, 5};
    printf("%d %d \n", arr[2], *(arr + 2));
    return 0;
}
  • A3 3
  • B2 2
  • CCompilation Error
  • DUndefined Behavior
Correct answer: A

Explanation

arr[2] and *(arr + 2) both give the third element, 3, so the output is "3 3".

Discussion 0

Nobody has replied yet. Start the discussion!