What is the difference between goto and long jmp( ) and setjmp()? Ans. A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program. A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a labeled position to jump to. This predefined position must be within the same function. You cannot implement gotos between functions. Here is an example of a goto statement: void bad_programmers_function(void) { int x; printf('Excuse me while I count to 5000...\n'); x = 1; while (1) { printf('%d\n', x); if (x == 5000) goto all_done; else x = x 1; } all_done: printf('Whew! That wasn't so bad, was it?\n'); } This example could have been written much better, avoiding the use of a goto statement. Here is an example of an improved implementation: void better_function(void) { int x; printf('Excuse me while I count to 5000...\n'); for (x=1; x - Study24x7
Social learning Network
14 Mar 2023 10:19 AM study24x7 study24x7

What is the difference between goto and long jmp( ) and setjmp()? Ans. A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind shou...

See more

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles