Discussion
The value of an automatic variable that is declared but not initialized will be
Answer: B
Correct answer: unpredictable
An automatic variable that is declared without an initialiser holds whatever happened to be in its stack storage, so its value is unpredictable - indeterminate, in the standard's term.
Reading it before assignment is undefined behaviour rather than merely a matter of luck: the compiler may assume it does not happen and optimise on that basis, so the observed effect need not even be a consistent garbage value. Static and external variables are the contrast, being zero-initialised before the program begins.
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