ExamVeda
Login
Home
This question belongs to C Program Pointer
Pointer
?

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    const int ary[4] = {1, 2, 3, 4};
    int *p;
    p = ary + 3;
    *p = 5;
    printf("%d\n", ary[3]);
}

Answer & Solution
Correct Answer: Option B
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Ganesh Paindla&#39;s
Ganesh Paindla&#39;s 3 years ago
Here array constant we can't change or modifies value inside it, but we can do using address, we use pointer store the ith element address in pointer ( *ptr = array + 3 => arary + 3*sizeof(int)), after that we deference that address and update ith element in array ( *ptr = 5), it will directly

ary[4] = {1, 2, 3, 5};