VOOZH about

URL: https://www.geeksforgeeks.org/c/c-setjump-and-longjump/

⇱ C setjump and longjump - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C setjump and longjump

Last Updated : 11 Mar, 2023

“Setjump” and “Longjump” are defined in setjmp.h, a header file in C standard library.

  • setjump(jmp_buf buf) : uses buf to remember the current position and returns 0.
  • longjump(jmp_buf buf, i) : Go back to the place buf is pointing to and return i.

Output
Geek4
Welcome to GeeksforGeeks
Geek3

The main feature of these functions is to provide a way that deviates from standard call and return sequences. This is mainly used to implement exception handling in C. setjmp can be used like try (in languages like C++ and Java). The call to longjmp can be used like throw (Note that longjmp() transfers control to the point set by setjmp()). 

Comment
Article Tags:
Article Tags: