C Questions and Answers – Non-Local Jumps – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Non-Local Jumps – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. The header file setjmp.h is used to __________
a) set location specific information
b) control low-level calls and returns to and from functions
c) handle signals reported during a program’s execution
d) manipulate strings (character arrays)
View Answer

Answer: b
Explanation: The header file setjmp.h is used to control low-level calls and returns to and from functions.

2. The void longjmp( jmp-buf env, int val) function causes setjmp() macro to return _______ value; if val is 0.
a) zero
b) one
c) null
d) no return
View Answer

Answer: b
Explanation: The longjmp() function cannot cause the setjmp() to return value zero,if the variable val is zero. It always return one when the value of val is 0.
advertisement
advertisement

3. Which is the true statement with respect to the function longjmp()?
a) the function where setjmp() was called has terminated, then the results are undefined
b) the function where setjmp() was called has terminated, then the results are defined
c) the function where jmp_buf was called has terminated, then the results are undefined
d) the function where jmp_buf was called has terminated, then the results are defined
View Answer

Answer: a
Explanation: The longjmp() function restores the environment saved by the most recent invocation of the set jmp macro in the same invocation of the program, with the corresponding jmp buf argument. The behavior is undefined, if there has been no such invocation, or if the function containing the invocation of the setjmp() macro has terminated execution in the interim.

4. Which of the given statement is not true with respect to void longjmp( jmp-buf env, int val)?
a) The variable value cannot be zero
b) env is the object containing information to restore the environment at the jmp_buf’s calling point
c) This function does not return any value
d) This function restores the environment saved by the most recent call to setjmp() macro
View Answer

Answer: b
Explanation: In the function void longjmp( jmp-buf env, int val), env is the object containing information to restore the environment at the setjmp’s calling point.

5. What is the function of the given longjump(jmp_buf buf, i)?
a) go back to place buf is pointing to and return i
b) go back to place buf is pointing to and return 0
c) uses buf to remember current position and returns 0
d) uses buf to remember current position and returns i
View Answer

Answer: a
Explanation: In the given function longjmp(jmp_buf buf,i), it goes back to place buf is pointing to and return i.setjmp(jmp_buf buf) uses buf to remember current position to and return 0.

6. How many times does the function longjmp() returns?
a) once
b) twice
c) thrice
d) never
View Answer

Answer: d
Explanation: longjmp() function defined under setjmp.h header file does not return any value.
advertisement

7. A less common use of setjmp.h is to create syntax similar to ____________
a) errno
b) variable arguments
c) coroutines
d) retval
View Answer

Answer: c
Explanation: setjmp.h is sometime is used to create syntax similar to coroutines. Coroutines are computer program components.

8. What will the following C statement do?

advertisement
#include < setjmp.h >
int setjmp(jmp_buf env);

a) save the current state of the registers into env
b) resets the registers to the values saved in env
c) provides a definition for env structure
d) accept variable(env) argument lists to be written
View Answer

Answer: a
Explanation: The given statement is used to save the current state of the registers into env. The state of the program is dependent on the contents of its memory(code, stack, globals and heap) and the contents of its registers.

9. What are the contents of the register?
a) sp, fp only
b) sp only
c) fp, pc only
d) sp, fp, pc
View Answer

Answer: d
Explanation: The contents of the registers includes sp, fp and cp. sp, fp and pc stands for stack pointer, frame pointer, and program counter.

10. setjmp takes a jmp_buf type and different other type variables as input.
a) true
b) false
View Answer

Answer: b
Explanation: setjmp takes jmp_buf type variable as the only input.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.