Can
you write a c program without using main function?
We can write a c program without
using main function. We can compile it but we cannot execute a program without
a main function. Since in C execution of any program start from main function. Examples of c program without a main is all
the c library functions. Function printf
is an example of library function which has been written and complied without
using main function. To use or run such functions we write other program using
main function and call those functions.
19 comments:
nice!!!!!!!!!!!
#include
class test
{
public:
test(){
exit(1);
};
} ;
test worker;
hi i am only saying that you r talking about c and using class that does not exist in c
not possible in gcc compiler
then plz give the code.
solution:
#include
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("program without main function");
return 0;
}
Explanation:
The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m, s, u and t into msut). The logic is, when you pass (s,t,u,m,p,e,d) as argument it merges the 4th, 1st, 3rd and the 2nd characters (tokens).
Note :
we can't write a C program without a main function. Here, we are just playing a gimmick that makes us believe that the program runs without the main, but there actually exists a hidden main function in the program. Here, we are using the pre-processor directive to intelligently replace the word “begin” by “main”. In simple words: int begin = int main
Good work keep it on
Amazing info :)
really great
Good logic. Appreciate it.
#include
#define begin main
void begin()
{
printf("Chinna");
}
very nice explanation....
#include
#include
#define m(h,a,n,m,t,i) h##i##m##n
#define mn m(m,b,n,i,c,a)
void mn()
{
printf("\n C progrsmming");
getch();
}
in GCC compiler
#include stdio.h
#include stdlib.h
f()
{
printf("I can able write program w.o.t main function\n");
exit(0);
}
1)save it as name.c
2)cc -nostartfiles name.c
3)./a.out
1000% working
Its working...!
#include
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("program without main function");
return 0;
}
plzz tell me this code syntax...
plzz tell me syntax
#include
#include
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("program without mainfunction");
return 0;
}
Using a macro that defines main
#include
#define fun main
int fun(void)
{
printf("Geeksforgeeks");
return 0;
}
p/o:-->> Geeksforgeeks
Post a Comment