Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Ponto de Entrada de um Programa | Introdução
Introdução ao C++
course content

Conteúdo do Curso

Introdução ao C++

Introdução ao C++

1. Introdução
2. Variáveis e Tipos de Dados
3. Introdução aos Operadores
4. Introdução ao Fluxo de Programas
5. Introdução às Funções

bookPonto de Entrada de um Programa

Todo programa em C++ deve ter uma função main(). A sintaxe dela se parece com isto:

cpp

main

copy
1234
int main() { return 0; }

Nota

A declaração return 0; é opcional no final da função principal. Se omitida, o compilador irá inseri-la automaticamente.

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?

Selecione a resposta correta

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?

Selecione a resposta correta

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?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2
some-alt