No u can't do a program without main function.When u compile the program u will not get any error message.But when u run the program the compiler will serach for the main function to be executed first.At that time u will get a error message.As your program may contain many functions the compiler will first search for the main function inorder to avoid the confusion as which function must be called first.


see like C programs ,execution of all C++ programs begins at main()function and ends at the return statement.

Structure of C++ program is as follows:


so you can not write a c++ proram with out main function. clear your basic
<<plug removed>>

Kolla Sanjeeva rao

Edited 6 Years Ago by Nick Evan: plug removed

>can u do a c++ program without main function.....?
It's splitting hairs, but yes, you can if your compiler supports alternative entry points. For example, Microsoft's CL compiler supports WinMain as an entry point instead of main.

GCC's linker supports alternate entry point names

ld - The GNU linker

-e entry
Use entry as the explicit symbol for beginning execution of your
program, rather than the default entry point. If there is no
symbol named entry, the linker will try to parse entry as a number,
and use that as the entry address (the number will be interpreted
in base 10; you may use a leading 0x for base 16, or a leading 0
for base 8).

Edited 6 Years Ago by gerard4143: n/a

I hadn't actually tried to compile it, but it does use some preprocessor directives to change the InfernoDevelopment() into main(). So, there is still a main() once the program compiles, it's just obfuscated in the source, so bravo to pradeep. However, this could have been 100x better if he/she offered some explanation and wasn't shamelessly self promoting.

And it also got deleted.

Do not mention, plug or refer to any product, service, or website you are affiliated with anywhere outside of Business Exchange forums specifically designated for this purpose


Thanks Santa!
This article has been dead for over six months. Start a new discussion instead.