- Preprocessor Directive accesses other libraries and file
- Main Function, its like the start/Update function all in one
- Declaration Statements Declare a variable, or changes to, while our Expression statements more or less just express predetermined variables.
- and return should always be 0
Revising an older version of a comment I made a long time ago:
1: The pre-processor directive is a statement to the compiler to load in data and code libraries from other sources/developers that allow us to use these existing libraries for our C++ program.
2: The main() function is one of the most vital statements needed for the program to run, as it tells the compiler all the important information it needs to know in order to run the program. Similarly, it also needs a return statement (typically return 0;) as a form of telling the compiler when to stop as it returns the value 0 to the compiler once it’s finished.
3: Declaration statements tell the compiler to store information that we can assign or change throughout the program’s life cycle, provided the values are assigned the values correctly in the order of the compilation. Similarly, expression statements can be used to tell the compiler to print out text strings to the console using namespaces through the use of the aforementioned per-processor directive
4: The return statement is to tell the compiler when to stop running the program with no errors.
What does our preprocessor directive do?
It is used to give instructions to the compiler before compilation.
Why do we have a main function?
int main () is required in every c++ script. The main function is the starting point of the code when its executed.
Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
Our expression statements so far have been the core narrative to the game and also the code that is using information to print out variables.
Declarations are the code that we have used to identify our variables. The information from these declarations will be used by the compiler to know what certain words mean.
What does the return statement do?
It terminates the execution of a function
Here is my summary of what I think our code is doing so far:
Preprocessor Directives: #include
I believe the preprocessor directive in Triple X loads predefined code also called a library which allows the compiler access to added functionality. In this case the header file IOSTREAM, allows the program to input and output text to a cmd window. (These directives should be at beginning of my code).
Main Function and return: main() with a return value of 0.
I believe, the main function tells the compiler to begin processing statements (AKA start running the program). This function is required for any c++ program. The return statement within the Main function returns a value of 0 to the compiler, indicating successful completion of the program. I think that any other return value could result in unexpected behavior.
Expression and declaration statements:
The first 2 expression statements (std::cout) use namespace standard to output text to the cmd window which provides the user a story of Triple X.
The first 3 declaration statements (const int) are used to declare and initialize 3 constant variables to perform calculations later on in Triple X.
The next 2 declaration statements use the above constant variables. To do this 2 variables (const int sum and const int product) are first declared and then initialized by performing calculations using the first 3 constant variables (const int a, const int b, and const int c).
Our last 2 expression statements so far in Triple X again use the standard namespace and utilize the cout command to output the results from (const int sum and const int product) calculations to the cmd window.
Finally, the return statement. This tells the OS whether the program successfully completed (value will always be 0 if it completed successfully).
1 - What does our preprocessor directive do?
The preprocessor directive allow us to use a library, in our case we use the library iostream.
2 - Why do we have a main function? What does it’s return statement do?
The main function indicates the beginning of our program, everything outside of the main function wont be recognized.
Return statement indicates that the program ends.
3 - Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
We have declared the 5 variables and print 4 lines of expression in our program.
What does our preprocessor directive do ?
I gues it is library or binary to make codes are properly working
Why do we have a main function? What does it’s return statement do?
Main function is the main part to be processed, it is a function like others we code. However this one is assigned to initialize our code
-
Preproscessor Directive: This is examining the code that we’ve written before any kind of compilation begins and resolves the directives before code is generated.
-
Main Function: This line just initiates the declaration of a function, or what we have coded in between the { }.
-
Declaration Statements: The declaration statement is what defines a variable for some sort of value like the numbers and letters we are using in this assignment.
-
Expression Statements: Expression statements are basically function calls or assignments.
-
Return Statement: This is the ending to the script which stops the execution and returns to a calling function.
Preprocessor Directive: Is a code library that establishes a connection for us to “include” certain things in our code, such as std::cout.
Main Function: This is the basis for every c++ program, without this, our code in C++ won’t run.
Expression Statements: In terms of our gameplay, they are showing the player the text that invites them in to play. Such as instructions.
Declaration Statements: As it states, it is declaring something in our code, such as variables. Example. It is saying that a does equal 4, b equals 3, and so on and so on.
Return Statement: This is telling the command console to return the code…I think. Still unsure, but essentially, its sort of like an output for our code.
Explains the code
The Preprocessor Directive - is a liberary for use in a code, and is here we can put more librarys according what we wish to command.
Main function - is the function that run all the code and return 0 is to say the program is running fine and didn’t run into errors, if comes to zero, will appear an error.
Declaration statements- where variables are created, and also can add value to them.
Expression statment- is a code when end with a semicolon at the end of the line.
Regards
Ana Reis
What does our preprocessor directive do?
It’s an instruction to the compiler to include a specific library before compiling. We’re using whatever info is in that library - in this instance, we’re using < iostream > as the Header file.
Why do we have a main function?
C++ requires a main function and the OS will look for it - without the main(), the code won’t work.
What does its return statement do?
We return to 0 to show that the program has run successfully, without errors. 0 shows it can be safely exited - if it were any other number, it would thrown an error.
Explain our expression and declaration statement that we have written so far.
The expression statements are telling the code the strings that need to be shown in the terminal. the std::endl creates a break between lines so they are more easily readable.
The declaration statements are where we are assigning variables with specific values which we can refer to later on in the code, such as calculating the sum or product of the integers.
Right, so I need to explain what I think the following means in my own words:
Preprocessor directive
I’m not exactly sure if there are other possibilities here than #include but on a whole I’d say this is where you would state some (external?) requirements the file might have. In the case of the assignment here it needs to know we need some functionality that supports in/outputting stuff from the command line. Perhaps this is also where other files get included later?
Main function
As I was told before in the lessons, every C++ program needs a main function as it’s the first function that gets called and I would assume that from here on out whatever else that follows will ultimately have it’s roots traced back here.
Expression statement
Statement that expresses something. Some form of output is given here.
Declaration statement
Statement that declares something. Like a variable or a constant. As in “I hereby declare that x is from now on known to be an integer with the value 9”.
Return statement
Statement that returns whatever value it is given. Probably the end of every function? At least that’s what my web development coding knowledge tells me. Don’t know what kind of trickery C++ has up its sleeve.
What does out preprocessor directive do?
Gives instruction to the compiler by loading the codes from another library prior to the your code being compiled.
Why do we have a main function? What does it’s return statement do?
Every program must have a int main() or it will not run. the main function tells the compiler what the program does. The return statement shows us if there is any errors in our code by feeding back the 0 we wrote in meaning no errors or by giving something other than 0 meaning there was an error.
Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
- First we expressed a few lines of code
- Then, we declared our variables by assigning values to them.
- We finally expressed with code that we wanted the sum and product of the values of our variables.
The preprocessor directive is including the code from the <iostream>
library.
The main function is essential for any C/C++ program. It is where the program starts. The return statement returns the 0 to the operating system, indicating that the program ran correctly.
The expressions statements are only printing strings and variables to the screen in this case.
The declaration statement is just declaring and initializing constants in this case.
Very well organized answer.
The preprocessor has other directives like #define
, #if
, #endif
, etc. I have a difficult time finding like a mini-course or some sort of short tutorial for the preprocessor. Until now, I have only used it to make code cross-platform (using conditional compilation). Of course, in addition to #include
and #define
(the last one is just like using const
, look it up if you are interested).
include - tells the preprocess to add the iostream library to our program (enables us to do input / output to the terminal).
main - required function in EVERY C++ program. It is the starting point for our program, it executes from this point.
expression statements - end with semi-colon, sometimes used to give the user instructions or results during program execution.
declaration statements = declare / instantiate constants, variables.
return statement - shows the success or failure status of our program at runtime.
the predecessor directive gives the information about the library which will be used. the main function marks the start of the function. the return statement marks the end of the function. expression statements express something into the terminal, while the declaration statements define and declare something.
Hi Gavin,
Preprocessor Directive: Starts the program and the code.
Functions: Hold data to help organize the code and draw on later from other places.
Expression Statements: Say what we want the code to do.
Declaration Statements: Prepare data to be used ahead of time in the code.
Return Statements: Returns the value back to the function of main().
Preprocessor Directive: includes any libraries that our program may need (in this case iostream is for outputing to terminal)
Function main: “main” required function in every program; let’s compiler know when the program should end.
Expression Statements: any line of code that ends in semicolon, other than variable declation statements; usually print to terminal commands, and manipulations of declared variables.
Declaration Statements: creating variables (to reserve in memory);
Return Statements: Returns a value for function main(), zero meaning the code is completed successfully and terminates it(?)
From my understanding, the preprocessor directive tells the IDE to choose from a specific library of statements. The main function is important because it’s the primary loop of the program. The return statement returns the logic back to the mainstream and can return a value, string, or even nothing at all. The declaration is extremely important for values that will be represented by variables. Whether they change or whether they stay consistent is all in the declaration. After a variable is declared, it will need to be initialized by giving it a starting value. So far, in the program we are writing, we have two output statements to the user prompting them to put in a code. Obviously, we haven’t gotten to the user input section, but right now, we have three variables listed as whatever number we feel like inputting. We also have two formulas set up to find the product and the sum of the variables. By writing the formulas only once, we can change the output of the product and sum by changing the numbers for the variables whenever the need arises.
Preprocessor directive instructs the compiler to add the codes from another library.
We have a main function because all c++ programs need a main function to run. The program cant run without a main function.
The return statement returns the value from the end of the main function to signal the end? Ill get it as we go along.
We declare our variables so that we may use numbers for the code to become super mega duper hackers? And the expressions are the lines ended in semicolons