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
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
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.
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
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
Explanation: The setjmp() macro returns zero if the return is from a direct invocation.
5. A non-zero value is returned, if setjmp() returns from a longjmp() function call.
a) false
b) true
View Answer
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
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
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
Explanation: The only function defined under the header file setjmp.h is longjmp().LONGJMP() resets the registers to the values saved in an environment.
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
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
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.
- Check Computer Science Books
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Check C Books
- Apply for C Internship