(A) 2 5
(B) Garbage Value
(C) Compiler Error
(D) Segmentation Fault
Explanation: The program prints “2 5″.
Since compilers convert array operations in pointers before accessing the array elements, (a+1) points to 2.
The expression (&a + 1) is actually an address just after end of array ( after address of 5 ) because &a contains address of an item of size 5*integer_size and when we do (&a + 1) the pointer is incremented by 5*integer_size.
ptr is type-casted to int * so when we do ptr -1, we get address of 5
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.