C | Pointer Basics | Question 16

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr;
    ++*p;
    p += 2;
    printf("%d", *p);
    return 0;
}

chevron_right


(A) 2
(B) 3
(C) 4
(D) Compiler Error


Answer: (B)

Explanation: The expression ++*p is evaluated as “++(*p)” . So it increments the value of first element of array (doesn’t change the pointer p).

When p += 2 is done, p is changed to point to third element of array.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.