The main function in C and how the main function is called

Source: Internet
Author: User

The main function is a special function in C, and the C program is always executed from the main function, and the prototype of the main function is:

1 int Main (intchar *argv[]);

Where ARGC is the number of command-line arguments, argv is an array of pointers to the parameters.

When the kernel executes a C program (using an EXEC function), a special startup routine is called before calling main (what ghost?). )。 Executable files Specify this startup routine as the starting address of the program-this is set by the connection editor, and the connection editor is called by the C compiler. The start routine takes command-line arguments and environment variable values from the kernel, and then arranges for calling the main function as described above.

The approximate process is as follows:

http://blog.csdn.net/sxh741/article/details/54970085 This link is pretty clear.

Http://www.cnblogs.com/findumars/p/6417932.html is about what the C + + main function does before it executes.

1, first to see a simple C program (SIMPLE.C) as an example to explain

2. Compiling

Gcc-o Simple simple.c

3. View the basic information of the executable file

Objdump-f Simple

4. What is Elf

5, about the starting address

The main function in C and how the main function is called

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.