C Questions and Answers – Non-Local Jumps – 1

«
»

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

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

advertisement

1. Which of the following header file defines one function longjmp(), and one variable type jmp_buf?
a) stdarg.h
b) locale.h
c) setjmp.h
d) stdlib.h
View Answer

Answer: c
Explanation: setjmp.h header file defines the macro setjmp(), one function longjmp(), and one variable type jmp_buf.

2. Which of the given options is an array type used for holding information?
a) longjmp
b) setjmp
c) jmp_buf
d) no such variable
View Answer

Answer: c
Explanation: jmp_buf is an array type used for holding information of macro setjmp() and function longjmp().This is a variable type defined under the header file setjmp.h.
advertisement
advertisement

3. Which macro saves the current environment into the variable environment for later use by the function longjmp().
a) setjmp
b) longjmp
c) jmp
d) set_jmp
View Answer

Answer: a
Explanation: The setjmp() macro saves its calling environment in its jmp-buf argument to be used later by the longjmp() function.

4. If setjmp() macro returns directly from the macro invocation, it______
a) returns zero
b) returns non-zero
c) produces error
d) nothing can be said
View Answer

Answer: a
Explanation: The setjmp() macro returns zero if the return is from a direct invocation.
advertisement

5. A non-zero value is returned, if setjmp() returns from a longjmp() function call.
a) false
b) true
View Answer

Answer: b
Explanation: The setjmp() macro returns a nonzero value, if the return is from a call to the longjmp() function.

6. Select the correct declaration of setjmp().
a) int setjmp(jmp_buf environment)
b) int setjmp(long_jmp environment)
c) int setjmp(jmp_buf )
d) int setjmp(long_jmp)
View Answer

Answer: a
Explanation: Declaration of the macro setjmp() is int setjmp(jmp_buf environment). ’environment’ is a the object of type jmp_buf.
advertisement

7. How many times can the macro setjmp() return?
a) one time
b) two times
c) three times
d) many times
View Answer

Answer: b
Explanation: setjmp() macro returns twice. First time, setjmp() returns zero on its direct invocation. Second time macro returns when longjmp is called with the information written to the environment; now, it returns the value passed to longjmp as second argument.

8. longjmp() function is the only function defined under the header file setjmp.h?
a) true
b) false
View Answer

Answer: a
Explanation: The only function defined under the header file setjmp.h is longjmp().LONGJMP() resets the registers to the values saved in an environment.
advertisement

9. Which function restores the environment saved by the most recent invocation of the setjmp() macro in the same invocation of the program?
a) jmp_buf
b) longjmp
c) jmpbuf
d) long_jmp
View Answer

Answer: b
Explanation: longjmp() is the only function defined under the header file setjmp.h. What setjmp() does is save the contents of the registers so that longjmp() can restore the contents later.

10. Choose the right declaration of longjmp() function.
a) void longjmp(jmp_buf environment, int value)
b) void longjmp(setjmp environment, int value)
c) void longjmp(int value, jmp_buf environment)
d) void longjmp(int value, setjmp environment)
View Answer

Answer: a
Explanation: The right declaration of the function longjmp() is void longjmp(jmp_buf environment, int value). This function works in pair with setjmp() macro.

Sanfoundry Global Education & Learning Series – C Programming Language.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
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 | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.