Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer What is Function in C++? | Introduction
Quizzes & Challenges
Quizzes
Challenges
/
C++ Functions

bookWhat is Function in C++?

Note
Definition

A function is a block of code designed to perform a specific task.

You've already seen this with the special main() function, which serves as the entry point of every program. However, you can also create your own functions to organize and reuse code efficiently.

main.cpp

main.cpp

copy
1234567891011121314
#include <iostream> // Function to add two numbers int add(int a, int b) { return a + b; } int main() { // Calling the `add` function int result = add(3, 4); std::cout << result << std::endl; }

The add() function is defined to take two numbers, add them together, and return the result. This function is then called inside the main() function, and the result is printed to the console.

question mark

What is the main purpose of a function?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 1

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 5

bookWhat is Function in C++?

Veeg om het menu te tonen

Note
Definition

A function is a block of code designed to perform a specific task.

You've already seen this with the special main() function, which serves as the entry point of every program. However, you can also create your own functions to organize and reuse code efficiently.

main.cpp

main.cpp

copy
1234567891011121314
#include <iostream> // Function to add two numbers int add(int a, int b) { return a + b; } int main() { // Calling the `add` function int result = add(3, 4); std::cout << result << std::endl; }

The add() function is defined to take two numbers, add them together, and return the result. This function is then called inside the main() function, and the result is printed to the console.

question mark

What is the main purpose of a function?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 1
some-alt