Discussion
Will the program compile in Turbo C?
#include <stdio.h>
int main()
{
int a=10, *j;
void *k;
j=k=&a;
j++;
k++;
printf("%u %u\n", j, k);
return 0;
}
Answer: B
Correct answer: No
Arithmetic on a void * is not allowed, because the compiler would have to know the size of the pointed-to type to advance the pointer, and void has none. So k++ is the offending line. The j++ above it is perfectly legal and advances by the size of an int. GCC permits void arithmetic as an extension, treating the size as one, but it is not standard C.
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