Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we have different versions of main functions in c++? [duplicate]

Tags:

c++

Possible Duplicate:
What is the difference between _tmain() and main() in C++?

How the void main(...), int main(..) and int _tmain() differs. They all are single entry and single exit systems. But in what situations we use these start-up functions?

like image 791
Sivaraman Avatar asked Oct 15 '12 09:10

Sivaraman


People also ask

What will happen if we use main function twice?

As far as having two main()'s, you can't really do that, since you'd get a link error (duplicate function name). But you can have several functions that are similar to main() but called something else, and main() calls them (like in your example).

Can there be 2 main functions in C?

it's not possible in c to have more than 1 main-function. you could use preprocessor directives like "#ifdef" to compile just one main-function at the time.

How many main functions are there in C?

The Main Function in C Programming By default, the return type of the main function is int. There can be two types of main() functions: with and without parameters. Note: We can write a program without the main function, but it is a frowned-upon practice.

Can two functions have the same name in C?

Function overloading is a feature of a programming language that allows one to have many functions with same name but with different signatures.


1 Answers

void main() is invalid; the C++ standard requires main to return int. Some compilers let you get away with it.

int main() is one of the two standard forms. The other is int main(int argc, char *argv[]), which can be used to receive command-line arguments. Implementations may permit other forms, but are not required to -- but all such forms must return int.

int _tmain() is specific to Microsoft.

like image 186
Keith Thompson Avatar answered Oct 19 '22 02:10

Keith Thompson