Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen 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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 1

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

What are the five core components of a function in more detail?

Can you give an example of a general function in C?

Why is the return value important in a function?

Awesome!

Completion rate improved to 2.63

bookStructure of the Function

Swipe um das Menü anzuzeigen

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 1
some-alt