Conteúdo do Curso
Introdução ao C++
Introdução ao C++
Ponto de Entrada de um Programa
Todo programa em C++ deve ter uma função main(). A sintaxe dela se parece com isto:
main
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.
main
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
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.
main
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.
Obrigado pelo seu feedback!