Discussion
Point out the compile time error in the program given below.
#include <stdio.h>
int main()
{
int *x;
*x=100;
return 0;
}
Answer: C
Correct answer: No error
The compiler has nothing to object to: x is a pointer to int and 100 is an int, so *x = 100 is well typed. The fault is at run time, not compile time - x was never given a value, so the assignment writes through an indeterminate address. This is the distinction the question is testing: a program can be perfectly legal and still crash.
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