1. Home
  2. Computer Science MCQs
  3. C Programming
  4. After longjmp returns control to the setjmp point, what is…

Added 30 Nov -0001

After longjmp returns control to the setjmp point, what is guaranteed about non-volatile automatic variables of the function that called setjmp?

  1. They keep their latest modified values because the stack frame is never touched
  2. They are reset to zero, since longjmp reinitialises the function's automatic objects
  3. Their values are indeterminate if they were modified between setjmp and longjmp Correct answer
  4. 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

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs