Google Add

Search

Write a C Program Without Main Function

Write a C Program Without Main Function.

In c program, nothing can run without main function so how to write a program which run without main function.

Using Macro


#include <stdio.h>

#define func main

void func(){


   printf("Hey i am running without main function");

}


What's the logic behind it.

In c Program is scanned from Left to Right and from Top to Bottom . So when program is scanned internally func is replaced by main.

Use Token Merging Operator


#include<stdio.h>

#define func m##a##i##n

void func(){
 printf("Hey i am running without main function");

}


Using ‘##‘ (token merging operator) operator we can merge two or more characters with it.

Tricky Problems

No comments:

Post a Comment