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

Which of the following statements are true after execution of the program.
void main()
{
   int a[10], i, *p;
   a[0] = 1;
   a[1] = 2;
   p = a;
   (*p)++;
}

Answer & Solution
Correct Answer: Option B
After the execution of the program, the value of the first element of the array 'a' will be modified. Let's break down the code step by step:

a[0] = 1;: Sets the first element of the array 'a' to 1.
a[1] = 2;: Sets the second element of the array 'a' to 2.
p = a;: Assigns the address of the first element of the array 'a' to the pointer 'p'.
(*p)++;: Increments the value at the memory location pointed to by 'p'. Since 'p' points to the first element of 'a', it increments the value of 'a[0]'.

After the execution of the program, the value of a[0] will be 2.

Therefore, the correct statement is Option B: a[0] = 2.
Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Ajay Maurya
Ajay Maurya 3 years ago
void main()
{
int a[10], i, *p;
a[0] = 1; // suppose base address is 1000
a[1] = 2; // address of 1 index will be 1004
p = a;//will contain base address of array so pointer will contain base address(1000);
(*p)++;//*p mean value at address which contain by the pointer p(contain address 1000 means value at this address=1).
//It will replace like (1)++ or 1++ means post increment operator that meaning is use first then increase.
Hence output will be 1.
}
Devika Patil
Devika Patil 4 years ago
acccording to precednace 1st bracket will evaluate..*P is 1....now post icrement ++ will perform,so value become 2..*P=2
Bhaumik Patel
Bhaumik Patel 9 years ago
*p++ =(*p)++ ans will be same then how the value change in above equation