Structure of the FunctionStructure of the Function

A function is a subroutine with its name created to perform a specific task.

In fact, you interact with features every day, there are features inside your brain and in the world around you.

For example, you are about to open a door, and your brain is working on a certain "open the door" pattern: the brain sends signals to the hand → the muscles in the hand contract and turn the doorknob down → the hand pushes the door → the door opens.

Any human skill or ability is a function a person can "call" when needed.

Modern life literally consists of functions: calling an elevator, lighting a speedometer in a car, scanning a product barcode, processing a radio signal from a rover, sending messages in a messenger, deleting a photo from a smartphone, and the list is endless.

Main function

Let me shock you, but all the time you've been taking this course, you've been writing code in one big main function in C, the main function. Why do C programs consist of a single function?

The main function in C is the entry point to a program. When you compile and run a C program, the operating system starts its execution from the main function. This means that the code written inside the main function will be executed sequentially.

The name main for the main function in C is a standard convention. This name was chosen by the designers of the C language as a common convention for the entry point of a program.

Structure of functions

Each function consists of five consecutive parts:

  1. Function type;
  2. Function name;
  3. Arguments;
  4. Function body;
  5. Return value.


Each part will be discussed in more detail in the following lessons.

General function structure:

Everything was clear?

Section 5. Chapter 1