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
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
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.
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
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
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
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
Explanation: longjmp() function defined under setjmp.h header file does not return any value.
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
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?
#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
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
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
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.
- Practice Computer Science MCQs
- Apply for C Internship
- Apply for Computer Science Internship
- Practice BCA MCQs
- Check C Books