Discussion
In C, which statement about static inside a function is correct ?
Answer: A
The correct statement is that its lifetime is the entire program.
A static variable declared inside a function has static storage duration: it is created once, before the program's main work begins, and lasts until the program ends. Its scope is still limited to the function, but it keeps its value between calls, which makes it useful for counters.
It is initialised only once, not on every call, so option B is wrong. It lives in the data (or BSS) segment, not on the stack, which is where ordinary local variables go. And it can be modified; a variable that cannot be changed is const, not static.
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