• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:


can i write a c program without main()
function  in the  program?
1 Solution
Sure for object or library files. You won't be able to execute it.
Standard C/C++ requires that every program have exactly one main() function.  (i.e. no more and no less. (The main function cannot be overloaded.))  So in stnadard C/C++ you cannot.

Note that you don't have to have a main in every translation unit (every source code file) just one for each project that is linked into a final program.   So standard C/C++ does allow you to compile source code files that don't contain main(), however You cannot produce a final linked program from this, you can only produce object code (astatic library) that may be linked to other projects to form a final program.

However some compilers break this rule--for good reason.  Windows compilers allow you to create windows programs that have a WinMain() function instead of a main() function.  They also allow you to create DLLs that don't have a main function.  
mohua_banerjeeAuthor Commented:
its superb.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now