Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Punto de Entrada de un Programa | Comenzando
Introducción a C++
course content

Contenido del Curso

Introducción a C++

Introducción a C++

1. Comenzando
2. Variables y Tipos de Datos
3. Introducción a los Operadores
4. Introducción al Flujo del Programa
5. Introducción a las Funciones

bookPunto de Entrada de un Programa

Todo programa en C++ debe tener una función main(). La sintaxis se ve así:

cpp

main

copy
1234
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.

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?

Selecciona la respuesta correcta

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?

Selecciona la respuesta correcta

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?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2
some-alt