Contenido del Curso
Introducción a C++
Introducción a C++
Punto de Entrada de un Programa
Todo programa en C++ debe tener una función main(). La sintaxis se ve así:
main
int main() { return 0; }
Nota
La declaración
return 0;
es opcional al final de la función principal. Si se omite, el compilador la insertará automáticamente.
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.
¡Gracias por tus comentarios!