Print a number 100 times without using loop, recursion and macro expansion in C

In this section we will see how to print a number 100 times in C. There are some constraints. We cannot use loops, recursions or macro expansions.

To solve this problem we will use the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions are like below.


#include <stdio.h>
#include <setjmp.h>
jmp_buf buf;
main() {
   int x = 1;
   setjmp(buf); //set the jump position using buf
   printf("5"); // Prints a number
   if (x <= 100)
      longjmp(buf, 1); // Jump to the point located by setjmp