After longjmp returns control to the setjmp point, what is guaranteed about non-volatile automatic variables of the function that called setjmp?
A
They keep their latest modified values because the stack frame is never touched
B
They are reset to zero, since longjmp reinitialises the function's automatic objects
C
Their values are indeterminate if they were modified between setjmp and longjmp
Correct answer
D
Their values are reliably restored to the values they held at the setjmp call
Correct answer
C. Their values are indeterminate if they were modified between setjmp and longjmp
12 views
⚔️
Challenge a friend on C Programming
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
longjmp restores the saved environment but makes no promise about automatic objects that changed after setjmp, because the compiler may hold them in registers the jump never restores. Declaring such a variable volatile forces memory access and makes its value well defined after the jump. Open files and heap blocks are unaffected, so cleanup still belongs in explicit code.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ Given uint8_t a = 200, b = 100; what is the type and value of the expression a + b in a typical C implementation? Next MCQ › char dst[4]; strncpy(dst, "abcd", 4); is executed. What is the state of dst afterwards?