Neeraj Sharma
Neeraj Sharma
Branch Unspecified
16 Mar 2012

C Program without main()

Here's a C programming challenge: Can you write a C program without main()? If yes, post your code below and I will take a look.
Ankita Katdare

Ankita Katdare

Computer Science
7 years ago
Nick_Sharma
Can you write a C program without main() ??
We had a similar thread for JAVA.
Check : https://crazyengineers.com/community/threads/can-java-program-run-without-the-main-method.30106/

It is quite possible to write a C program without main() if we know how to use preprocessor and macro.
Neeraj Sharma

Neeraj Sharma

Branch Unspecified
7 years ago
Yes it is possible using macros.I wanted it to be a kind of quiz 😛 Sorry may be I posted in wrong section 😔
Ankita Katdare

Ankita Katdare

Computer Science
7 years ago
Nick_Sharma
Yes it is possible using macros.I wanted it to be a kind of quiz 😛 Sorry may be I posted in wrong section 😔
This is the right section. 👍
Let us keep this open for responses.
Neeraj Sharma

Neeraj Sharma

Branch Unspecified
7 years ago
This is actually the solution. Yes, we can write a program without main logically but it is not possible conceptually..
Here is the program:

#include<stdio.h>
#include<conio.h>
#define decode(a,u,d,i,b,l,e) i##a##d##u
#define START decode(a,n,i,m,a,t,e)
void START()
{
clrscr();
printf("Hey this is Nick waving hi from a program without main");
getch();
}

Share this content on your social channels -

Only logged in users can reply.