Explain the sections of the code

Preprocessor directive used to call the library

int main() is the function under which overall code runs

expression statement gives Output

Declaration statement helps to declare the values for the variables

Correct me if I am wrong

Someone, please explain why return 0; is used

So let’s keep it stupid simple.

Preprocessor Directive - tells the compiler that you want it to include things from a particular directory/ library on the computer.

int main () - the main function tells the compiler the primary thing you are trying to get it to do

expression statements - tell the compiler what things to show such as text and numbers that the end user can read in the terminal

deceleration statements - these declare what things are, such as the values for variables and their product and sums for the compiler to understand what you are referring to when you use a variable in your expressions for example

return 0 - this return statement is used to make sure that everything is running properly, so if the compiler does everything correctly, the returning statement should be 0, if it is any other value, then you know that something has gone wrong somewhere along the line.

That’s how I’ve understood it anyway. Feel free to correct me or give me feedback on your own understandings of it!

1 Like

Preprocessor Directive: Instructs the compiler to include the library of listed header files before executing main(). It allows this file to access and utilize the code within the library files.

Main Function: Every c++ program requires a main() in order to run. It tells the program what it’s job is. int main() indicates the function will return an integer.

Declaration Statements: Defining and initializing the variables. As the variables in main() are const, they will not be altered after initialization.

Expression Statements: These tell the compiler what to do. In main() so far, these are printing output the terminal.

Return Statement: Returns a value to the operating system after executing the function. In this case, we are returning 0 as an exit status. 0 indicates the function was passed without any errors. Any other number would indicate an error.

2 Likes

Preprocessor Directive allows the file to use code from a library.

Main Function is required in order for C++ to run.

Declaration Statement declare what things are. This includes variable values, sums and products.

Expression Statement contains text and numbers you want to show

return 0 ends the program once it is finished running without any error.

1 Like

The preprocessor directive is a library of codes written by another programmer which is needed to compile and run the codes done by us.

The main function is where the coding actually starts. Without the main function the compiler will not work, there has to be the main function in during coding.

Declaration statements are used to declare “somthing”.

Expression statements are statements which contain a semicolon.

Return statement shows that the code that was run was true.

Preprocessor Directive - Adds a library of code that will be used.

Main Function -First function that will execute when the software is run. Must have.

Expression Statement - Not sure. In the video it said it was an expression statement because it ended with a ;. But so do the Declaration Statements. (Anyone?)

Declaration Statement - when you declare a variable exists. (I think this is also called initializing it??? but maybe that refers to setting its initial value. Anyone? Can you declare a variable without initializing it?)

Preprocessor directive: Is the section where we declare all the libraries we are using for this class.
Main function - The function that will execute all of our code
Declaration statements - Here we declare all variable data that we are using in our program.
Expressión statements - All the logic, that, at this time just prints things in console.
Return - Returning error code 0, therefore the compilation and runnning the program went good.

Privacy & Terms