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]);
}
#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]);
}
A. 4
B. 5
C. Compile time error
D. 3
Answer: Option B
Join The Discussion
Comments ( 1 )
Related Questions on Pointer
In C, what is a pointer primarily used for?
A. Decision making
B. Code organization
C. Variable declaration
D. Storing values
In C, how do you declare a pointer variable that can store the address of an integer?
A. int *ptr;
B. ptr int;
C. int ptr;
D. ptr *int;
What is the purpose of the '->' operator in C when used with pointers?
A. Arithmetic operation
B. Indirection operator
C. Member access operator
D. Bitwise operation
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};