Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Structure of the Function | Functions
C Basics

bookStructure of the Function

A function is a named subroutine that performs a specific task. You use functions all the time, even outside programming.

For example, when you open a door, your brain runs an open door routine: signal the hand β†’ turn the knob β†’ push β†’ door opens.

Just like that, every skill you have is a function you can call when needed.

The Main Function

Here's a surprise: throughout this course, you've been writing code within one significant function in C which is the main function. Why is it that C programs revolve around this single function?

The main function in C serves as the program's starting point. When you compile and run a C program, the operating system initiates its execution with the main function, meaning that the code within the main function gets executed in sequence.

The use of main as the principal function in C is a longstanding tradition, a convention chosen by the creators of the C language to signify a program's entry point.

Anatomy of Functions

Every function is structured around five core components:

  • Function type;
  • Function name;
  • Arguments;
  • Function body;
  • Return value.

A general function looks something like this:

main.cpp

main.cpp

copy
123456
func_type func_name(arguments) { // Core actions of the function // Resulting outcome after function execution return function_output; }
question mark

What is the purpose of the main function?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 2.63

bookStructure of the Function

Swipe to show menu

A function is a named subroutine that performs a specific task. You use functions all the time, even outside programming.

For example, when you open a door, your brain runs an open door routine: signal the hand β†’ turn the knob β†’ push β†’ door opens.

Just like that, every skill you have is a function you can call when needed.

The Main Function

Here's a surprise: throughout this course, you've been writing code within one significant function in C which is the main function. Why is it that C programs revolve around this single function?

The main function in C serves as the program's starting point. When you compile and run a C program, the operating system initiates its execution with the main function, meaning that the code within the main function gets executed in sequence.

The use of main as the principal function in C is a longstanding tradition, a convention chosen by the creators of the C language to signify a program's entry point.

Anatomy of Functions

Every function is structured around five core components:

  • Function type;
  • Function name;
  • Arguments;
  • Function body;
  • Return value.

A general function looks something like this:

main.cpp

main.cpp

copy
123456
func_type func_name(arguments) { // Core actions of the function // Resulting outcome after function execution return function_output; }
question mark

What is the purpose of the main function?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 1
some-alt