Skip to content
Home » C Program Without Main() Function using Macro and Token-pasting Operator (##)

C Program Without Main() Function using Macro and Token-pasting Operator (##)

Learn about C Program Without Main() Function using Macro and Token-pasting Operator (##) in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

The token pasting operator(##) merges d, c, l, and an into “dcla” when the macro fun(c,o,d,e,x,a,m,p,l) is expanded as “dcla.” When we pass macro fun(c,o,d,e,x,a,m,p,l) as an argument, it merges the 3rd, 1st, 9th, and 6th characters (tokens). It is worth noting that no characters (tokens) are repeated in fun(c,o,d,e,x,a,m,p,l).

Now, in the next line of the program, The preprocessor substitutes the expansion fun for the macro “display” (a,b,m,d,e,n,g,h,i). According to the macro definition in the preceding line, the argument must be expanded so that the third, first, ninth, and sixth characters are merged. The third, first, ninth, and sixth characters in the argument fun(a,b,m,d,e,n,g,h,i) are m, a, I and n. As a result, the preprocessor replaces “int show” with “int main” before passing the program to the compiler.

C Program Without Main() Function using Macro and Token-pasting Operator (##)

#include<stdio.h>
#define fun(c,o,d,e,x,a,m,p,l) d##c##l##a
#define show fun(a,b,m,d,e,n,g,h,i)
int show()
{
  printf("Code Example.\n");
  return 0;
}

Output:

Code Example.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program Without Main() Function using Token-pasting Operator (##)
C Program Without Main() Function using preprocessor