My overview of the Code Structure and Meaning

1) Preprocessor Directive
e.g.

#include <iostream>

When compiling, this part of the code tells the compiler to add before the rest of the code some other code from a library. This is needed to allow some functions from the libary to be used in the rest of the code.

2) Main Function
e.g.

int main()

This contains all the code to run. Without it, code cannot run.

3) Expression Statements
e.g.

std::cout << "You are a thief who is about to break into a bank at midnight...";

std::cout << std::endl;

std::cout << "The front door is padlocked, you need to hack it to continue...";
std::cout << std::endl;

std::cout << sum << std::endl;

std::cout << product << std::endl;

This is where instructions for making outputs in the terminal are run.

4) Declaration Statements
e.g.

const int a = 4;

const int b = 3;

const int c = 2;

const int sum = a + b + c;

const int product = a * b * c;

This is where variables are introduced so they can be used.

5) Return Statement
e.g.

return 0;

This is where the Main Function returns a value to show whether the code ran smoothly or has an error.

1 Like

You are on your way to becoming a great programmer.

Privacy & Terms