Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Точка входу в програму | Початок роботи
Вступ до C++
course content

Зміст курсу

Вступ до C++

Вступ до C++

1. Початок роботи
2. Вступ до операторів
3. Змінні та типи даних
4. Вступ до потоку програм
5. Вступ до функцій

book
Точка входу в програму

Кожна програма на C++ повинна мати функцію main(). Синтаксис виглядає так:

cpp

main

copy
1234
int main() { return 0; }

Примітка

Оператор return 0; є необов'язковим в кінці головної функції. Якщо його опустити, компілятор автоматично вставить його.

Note

The return 0; statement is optional at the end of the main function. If omitted, the compiler will automatically insert it.

Inside the main() function, you can start writing your code. Every expression should end with a ; symbol so the program can understand when one command finishes and the next one begins.

cpp

main

copy
1234
int main() { 5 + 5; }

Above you can see a simple expression. Expressions form the building blocks of statements and define how values are calculated or manipulated in a program. The one above don't involve variables, built it commands or anything complex but we will use all of it eventually in the future.

file1

file1

copy
123456
int main() { 5 + 5; 1 - 8; 9 / 3; }

You can write as many expressions as you want, but each has to have ; at the end. If you remove one from 5+5;c++ will see the expresison 5 + 5 1 - 8; which will not make sense to it and generate an error. But you can write all of your code in one single line if you want.

cpp

main

copy
1234
int main() { 5 + 5; 1 - 8; 9 / 3; }

If you run the code above, nothing will appear on the console. This is because the C++ might skip the calculation if it determines the result is unused. Moreover, there is no command to display or store the result.

1. What does the `return 0;` statement at the end of the `main()` function helps to identify?
2. What happens if you omit semicolons at the end of expressions within the main() function?
3. What happens if you omit semicolons at the end of expressions within the `main()` function?
What does the `return 0;` statement at the end of the `main()` function helps to identify?

What does the return 0; statement at the end of the main() function helps to identify?

Виберіть правильну відповідь

What happens if you omit semicolons at the end of expressions within the main() function?

What happens if you omit semicolons at the end of expressions within the main() function?

Виберіть правильну відповідь

What happens if you omit semicolons at the end of expressions within the `main()` function?

What happens if you omit semicolons at the end of expressions within the main() function?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2
We're sorry to hear that something went wrong. What happened?
some-alt