Подпрограммы (C++): различия между версиями
Перейти к навигации
Перейти к поиску
(Новая страница: «== Функции == * [https://www.w3schools.com/cpp/cpp_functions.asp Функции в C++ (w3schools)] * [https://www.cplusplus.com/doc/tutorial/functions/ Ф...») |
|||
Строка 2: | Строка 2: | ||
* [https://www.w3schools.com/cpp/cpp_functions.asp Функции в C++ (w3schools)] | * [https://www.w3schools.com/cpp/cpp_functions.asp Функции в C++ (w3schools)] | ||
* [https://www.cplusplus.com/doc/tutorial/functions/ Функции в C++ (cplusplus)] | * [https://www.cplusplus.com/doc/tutorial/functions/ Функции в C++ (cplusplus)] | ||
+ | |||
+ | <syntaxhighlight lang="c++" line> | ||
+ | #include <iostream> | ||
+ | |||
+ | void hello(char* name) { | ||
+ | std::cout << "Hello, " << name << "!\n"; | ||
+ | } | ||
+ | |||
+ | int add(int a, int b) { | ||
+ | return a + b; | ||
+ | } | ||
+ | |||
+ | int main() { | ||
+ | hello("Jack"); | ||
+ | int a = 2; | ||
+ | int b = 3; | ||
+ | int result = add(a,b); | ||
+ | std::cout << a << " + " << b << " = " << result; | ||
+ | return 0; | ||
+ | } | ||
+ | </syntaxhighlight> |
Версия 09:31, 25 июня 2021
Функции
1 #include <iostream>
2
3 void hello(char* name) {
4 std::cout << "Hello, " << name << "!\n";
5 }
6
7 int add(int a, int b) {
8 return a + b;
9 }
10
11 int main() {
12 hello("Jack");
13 int a = 2;
14 int b = 3;
15 int result = add(a,b);
16 std::cout << a << " + " << b << " = " << result;
17 return 0;
18 }