0

I Know Main is a primary funtcion in C...But Is there other reason ..like why they named it as main only and not other??? ..and why we have to write main() compulsory in prgoram...Any histroy behind it??
Help ME Please.......

3
Contributors
2
Replies
29
Views
4 Years
Discussion Span
Last Post by deceptikon
0

The function main() is most likely named "main" because it is the first function that you write which is called by the program's startup code. There is a bunch of code that you do not write which is executed first, then when it's done it calls main(). If main() were not a required function then the startup code would not know what function to call.

0

like why they named it as main only and not other???

That's an easy one. C inherited the name of the starting point from B.

and why we have to write main() compulsory in prgoram

A program must have a starting point. In assembly this constitutes an address offset that denotes where instructions will begin executing. In some higher level languages execution simply starts at the top of the file. Other languages like C don't allow execution statements at the top lexical level, so they define the starting point as a function with a known name and signature that the compiler or interpreter can call directly.

Ultimately, it's all about answering the question "how do I start this program?"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.