C Questions and Answers – Non-Local Jumps – 2

«
»

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

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.
advertisement

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.

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.
advertisement

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.

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?

#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.
advertisement

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.

advertisement

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn