Discussion
If int *p points to arr[2], then (p+1) points to
Answer: B
p + 1 points to arr[3].
In pointer arithmetic, adding 1 to a pointer moves it forward by one element of the type it points to, not by one byte. If p holds the address of arr[2], then p + 1 holds the address of the next int, arr[3]; the compiler scales the 1 by sizeof(int) automatically.
arr[1] would be p - 1. arr[2]+1 describes adding 1 to the value stored in arr[2], not moving the pointer, and the result can be determined exactly from the rules of pointer arithmetic.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development