Discussion
Will the following program give any warning on compilation in TurboC (under DOS)?
#include <stdio.h>
int main()
{
int *p1, i=25;
void *p2;
p1=&i;
p2=&i;
p1=p2;
p2=p1;
return 0;
}
Answer: B
Correct answer: No
All four assignments are legal without a cast. C converts implicitly in both directions between void * and any object pointer type, so assigning an int * to a void * and back again raises no diagnostic. It is C++ that requires an explicit cast when converting away from void *, and mixing up the two languages is what makes this question look harder than it is.
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