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

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?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 5.  1
some-alt