Explain our code so far in Triple X!

The preprocessor directive is like asking a librarian for a certain book, but the only way to know what book the librarian needs to look for is by giving the librarian the name of the book (the “Header File”). Imagine your writing an important essay for some class, the only way your going to write things that make sense is if you have the book with you, ready to flip to any page for facts and annotations; just like a compiler with expression and declaration statements. The main() function serves as a foundation for the code, like a validator, the return 0 is telling the main function " it ran successfully good job man" or “nicely written paper…it totally made sense” (lol teacher being the main() func). Declare to establish; express to; well… express :joy:. This is what I have managed to muster having no background in programming, Having a very splendid time though, the instructiveness in this course is just great. Thanks guys!

The Preprocessor calls in code from another code library, allowing us to use that code to program our file here. The main function is where we run all of our code so that it can be executed later and the return statement is so that the code can actually be executed without any errors.

Declaration Statements are like saying your the captain of a pirate ship, you’re DECLARING your status as the pirate captain like how we’re declaring these variables as a certain number or string. Expression Statements are like showing someone how you feel, like showing someone you love them by giving them a flower to EXPRESS your love for them like how we’re expressing that we want the compiler to print out our strings and numbers as well as perform breaks between lines.

Preprocessor directive loads necessary libraries for code

Main function is the function that will run in the C++ code

Expression statements is anything ending in a semicolon (std::cout, variable declaration etc.)

Declaration Statements: declare variables

Return statements: ends function

Constructive feedback always appreciated!

Preprocessor directive: It just includes a specific library of code before compiling. In our case that would be text input and output.

Main function and Return statement: Main function indicates that the following lines of codes will be executed and the Return statement allows the application to end. The 0 allow us to know if there has been any error by changing its value if its truly the case an error has occurred.

About our expression and declaration statements: We’ve basically written an introductory text to our game, defined some integers and then made them constant to secure the value of our variables. Then we’ve written some expression statements and included arithmetic operations as now constant integers.

did I got it?

In my own understanding:

The preprocessor directive calls on a library of existing code that perform predetermined actions or instructions which we can use in our code by entering the identifier (not sure if this word means something else).

The main function is a container for our code and lets the compiler know how where and how the code should be implemented/built. The return statement indicates the end of the programming instruction.

Our expression statements give context to the purpose of the executed code and the declaration statement enable the code to call on variables to perform calculations or potential interaction with the expression statements and code in general.

What does our preprocessor directive do?

It allows our program to use code that makes our program work. It copies the iostream library before our program is compiled, letting the computer know what our code means.

Why do we have a main function? What does it’s return statement do?

The main function is needed for our OS to know what to run at first. It is required in all C++ programs, as without it nothing will run. It’s return statement shows our OS that the main function exited with a value of 0, which means no error code. This is needed to exit out of the program safely.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

Our expression statements are the lines starting with std, which express something in the terminal. They let the program know that those lines need to be shown to the end-user. The declaration statements are for the program, for it to know what certain variables are equivalent to. Currently, our first 2 expression statements are showing the text to the user and ending the lines. The next declaration statements are declaring new variables to the program, and showing the program that they shouldn’t be changed. For our program, it is declaring the constant a, b, and c, and giving them a value. It is then declaring another constant sum, which is the sum of the 3 constants, and a constant product, which is the product of multiplication of those 3 constants. The program then prints out the sum constant and the product constant with 2 more expression statements and returning 0 to the main integer, which closes the program with no error code.

Preprocessor directive
The preprocessor directive brings premade code to our program run.

Main Function
The main function is telling our program what to do.

Expression Statements
The expression statements are telling the program what we want to do with our information.

Declaration Statements
The declaration statement is declaring information or values for when it is called in our expression statements

Return Statement
The return statement will end the program once it has completed our code.

This particular preprocessor directive enables the usage of the ‘std’ keyword for our terminal output.

Why we have a main function is that the computer will need a starting point of where we need to execute our code. The return statement is there to exit the program with the error code 0 as the int main() function needs a return value.

Currently the expression statements are being used to output our sentences and final values.
The declaration statements are used to initialize variables so that the variables will have an initial value to be modified unless they have the const keyword.

Overall the program is displaying a couple sentences and the sum and product values from the given variables in the code.

The preprocessor directive essentialy copies code into our code.
A main function is necessary in a c++ program, the compiler looks for it and won’t compile our code if it can’t find the main function. The return statement is used to tell that the program we created runs without errors.
Statements are the lines of code which ends with semicolon. Declaration statements are statementes which declare a variable, for example, it initializes something new into the code. The expression statements are the statements used to print some message to the screen or use a c++ tool, a statement that isn’t related to a variable declaration,instead, it makes use of one variable already declared and initialized.

Preprocessor directive - Directions to the compiler that take effect before absolutely everything else. Allows for pre-packaged data to influence how the rest of the code below it (ALWAYS and exclusively below it) to take effect properly.

Main function - The bread and butter, the function that is the core of our program, without which the program won’t even start trying.

Declaration statements - Define variables with the functions that can be called to serve various purposes.

Expression statements - Contain an expression and end with a semi-colon. It seems like they often speak to the terminal to produce an effect there. Like a way for the program to interact with things outside of itself.

Return function - returns an integer (so far) whose value will ultimately determine … something. Haven’t gotten there yet!

this copies code from an existing library for us to use in our code , or else it wont compile.

we have a main function because this is the function that C++ actually looks for when compiling or reading code, so it must be included or else the code wont compile.

the return statement returns an integer to signal if the code/program either succeeded or failed to run .

so far in our expression statements we’ve sort of written a story that will make the player aware of what their task is and how they can complete it .

in our declaration statements we’ve declared 3 variables: a,b,c and given them constant values ,which indicate they cannot be changed .

we have made a sum and product variable which do as their name says, the sum variable calculates the sum of a + b + c and the product variable multiplies a * b * c.

both of these are constant so they will not/can not be changed in our code either

#include lets us use the code somebody else wrote, in our case, several input and output commands, the main function is a function that every c++ code must have, and its the one that the computer runs, the first block of code of expression statements outputs text and set the story, the block of declaration statements is the one that we set our variables up in, the 2nd block of expression statements prints our variables, and the return expression returns 0 to the system, and tells it that all the code was executed

What does our preprocessor directive do?
It gives knowledge to the compiler about the library’s codes that we are gonna use and tell what each must do.

Why do we have a main function? What does it’s return statement do?
We have a main function 'cause without it the code cannot run, the return statement secure that the code has no error, if it gives a 0 it’s all ok, if not there is an error.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
We just printed some text into our compiler and assigned values to our declared variables. To summarise our program is printing some text that the player will read and also printing our variables that we’ve declared and assigned values to.

// not new to coding but I liked they way preprocessor directive was explained
// this first line has two parts preprocessor (do) and directive (what) so include the iostream library
//preprocessor directive (do what)
#include <iostream> 

// declaration statements typically declare variable types and sometimes can intialise them with a value
char ithink[30];
int thecode;

// main function is main all C/C++ programmes run main and won't compile  without one
int main()
{

// expression statements end in a semi-colon they execute code such as assigning a value to a variable or in this case printing to the console / terminal
     std::cout << "You are with Woody and The Big Green Foot." << std::endl;
1 Like

Preprocessor directive - Is telling us we are pulling code from another location or library and using it in our code.

Main Function - is required in order for a code to run sort of like and when I did some coding in highschool lol. The return statement is the program end part.

Expression Statements: These are posting text to the terminal. call out. Outputs to the terminal we also output values from our declared expressions.
Declared Expressions: This is stating what a function is such as a = 5; It is declaring a value for a named variable and functions.
Return - Is ending our program which is always 0.

1 Like

Preprocessor Directive has the function to include different libraries so as to allow us to print text etc
Main has a function to indicate that the body of our code has started and without main function our code wont be compiled
Expression Statements are statements which have an expression with a semi colon in the end
Declaration Statements are statements which have a declaration for e.g int a +6;

1 Like
  • Preprocessor directives get executed before code gets compiled. These are instructions for preprocessor before compilation takes place. For example: #include directive asks preprocessor to include/copy code of the given file in our source file. Another example of preprocessor directive is #define, #ifdef, #ifndef, #pragma etc.
  • main function is a very important function when our program is going to be exe. This function is the entry point of the execution. Our operating system will look for this main function when this program gets executed.
  • Return statement of a function marks the end of the function. Return statement of the main function returns zero to the caller (which is operating statement). After return statement gets executed, program execution gets stopped.
  • Any expression that ends with a semicolon is called expression statement. Any statement which declares the variables is called declaration statement.
  • We are printing some messages using expression statements to convey instructions to the player and declaring and initializing the variables (using declaration statements) that are used in our game.
1 Like

What does our preprocessor directive do?

It instructs the compiler to apply the contents of the header file onto the compiler

Why do we have a main function? What does it’s return statement do?

int main() 

is something that is required for programs to run

return 0 

Is to tell if there are any errors

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

Expression statement - any expression that is followed by a semicolon
Declaration statement - a statement that declares anything like variables

1 Like

The preprocessor directive is used to import existing codes into the new code we are developing.

In order for the operating system to run the code, there must be an int main(). If this is not present the code will not work. The return 0 statement is used as a check, if the int main() is executed without errors the 0 that is coded in will be sent back, otherwise it will recognize that an error has occured.

  1. The code prints the game dialog out
  2. We define the variables a, b, and c and then the sum and product
  3. The code prints out the sum and product on

So if I understand correctly our preprocessor directive just accesses and loads code from another library before our written code.

Every single program written in C++ needs a main function in order to run and the return statement checks for errors.

The expression statements we have written prints our custom text to the terminal. Then we have declared our values (our constants) of a, b, c, the sum of abc and the product of abc. After that we have expression statements printing our sum and product to the terminal.

Then of course we return to 0 to exit the function and check for errors.

Privacy & Terms