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.

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

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.
Free 30-Day Java Certification Bootcamp is Live. Join Now!

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.

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.

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

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
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.