Discussion
What will be the output of the program if the array begins at address 65486?
#include <stdio.h>
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u\n", arr, &arr);
return 0;
}
Answer: B
Correct answer: 65486, 65486
arr decays to a pointer to its first element and &arr is a pointer to the whole array. Both start at the same place, so both print 65486. They differ only in type, which shows up when you add to them: arr+1 moves by one int, &arr+1 by the whole array.
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