Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the main() function mean for a program

Tags:

c

What is so special about main() function in C? In my embedded C compiler it tells the program counter where to start from. Whatever appear first (as instruction) into main function it will be placed first in the flash memory. So what about PC programs? What is the meaning of main() when we program for PC?

like image 527
Radoslaw Krasimirow Avatar asked Oct 31 '25 08:10

Radoslaw Krasimirow


1 Answers

On a hosted implementation (basically, anything with an operating system), main is defined to be the entry point of the program. It's the function that will be called by the runtime environment when the program is launched.

On a freestanding implementation (embedded systems, PLCs, etc.), the entry point is whatever the implementation says it is. That could be main, or it could be something else.

like image 77
John Bode Avatar answered Nov 02 '25 23:11

John Bode