Hi! This is my first post here, and Iâve been asked to explain the distinct parts of the code seen in section 2, lecture 22 of Learn C++ and Make Video Games
The first element of our source code is the preprocessor directive, distinguished by being before the main function and having a unique syntax #include â<âa libraryâ>â - this code tells our compiler to include the library we referenced and is necessary so that other syntax is understood by the compiler.
Then our main function begins and all functions have 4 parts, they are: the return type in our case, itâs int (short for integer) followed by the function name (here, main) then the parameter list - the variables that we require in our function (they are optional in case of a main function) and they have to be written inside round parentheses â( )â.
After the parameter list, we have our function body represented by statements inside curly braces â{ }â. In our code so far weâve used three types of statements, expression statements - these are basic commands for the computer to do something like âcoutâ (character output to the console); declaration statements which allocate some space in memory (size depends on the variable type) assign a name, chosen by us, to that particular space in memory (we have a few naming conventions, for example your variable name cannot begin with a number, spaces in the name are not allowed and variables cannot have the same name as other commands); and, finally, the return statement which returns a variable of the type weâve used when declaring the function, afaik returning 0 in our main function used to be or still is (in case of a linux based os) a way for us to know that our code ran and ended successfully meaning that the compiler went through each line in order, found no issues with our syntax (no compile-time errors and for brevity no link-time errors). Itâs possible to have our code return 0 and also have logic errors though so returning a 0 doesnât mean our source code is bug free.
Thanks for reading my post and do know that any feedback is appreciated!