Correct option is D
The program defines a character array arr[] initialized with the string "FGHJKJGF". The pointer p points to the first element of the array (arr[0]). The expression *(p + 3) accesses the value at the position
3 indices ahead of p (0-based indexing).
Step-by-Step Execution:
1.
Array Initialization:
· char arr[] = "FGHJKJGF";
· The array arr is initialized with the string "FGHJKJGF".
2.
Pointer Initialization:
· char *p = arr;
· The pointer p points to the first element of the array arr.
3.
Print Statement:
· printf("%c\n", *(p + 3));
· This statement prints the character at the position p + 3.
· p is pointing to the first element of the array, i.e., arr[0].
· *(p + 3) accesses the element at index 3 of the array.
4.
Evaluating the Expression:
· The array arr is indexed as follows:
· arr[0] = 'F'
· arr[1] = 'G'
· arr[2] = 'H'
· arr[3] = 'J' (This is the 3rd index)
Therefore, the output of the program is:
(d) J
Important Key Points:
1. Pointer arithmetic in C allows direct access to elements in an array.
2. *(p + n) is equivalent to arr[n] when p points to the first element of the array.
3. String arrays in C are null-terminated (\0), but the null terminator is irrelevant here since it’s not accessed.
Knowledge Booster:
·
Pointer Basics:
· *p refers to the value at the memory location pointed to by p.
· p + n moves the pointer n steps forward (or backward if n is negative) in memory.
·
Array Access:
· arr[n] is equivalent to *(arr + n) in C.