Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

C++ Notes and rules

1. g++ is used to compile files (Make to computer understand).


2. ./ is to execute the file.
3. .cpp is the domain to the C++ type file, but it can also be .h.
4. To change the name of a compile file you need to use command “-o”.
5. To leave a single line comment use //.
6. For multi-line use /* to open and */ to close.
7. The domain for compiled C++ is .o
8. Variables in C++ are:
 int : integers or numbers
 double : floating-point numbers (decimal numbers)
 char : individual characters (it can also be special symbols like
@)
 string : more than one character
 bool : true or false values (0 or 1, on or off, yes or no)

9. To use C++ you need to declare the type of variable, e.g., :

Type of integer
int score;

End of variable
Name of variable

10. To set a value of a variable, you need to use = (assign) sign and to
follow, and the value that you want to put next.

11. You can just simply write int score = value; .

12. Computers can use the four basic maths signal ( + , -, /, *) and
percentage signal (%).

13.std::cout << score << "\n";

This code can be used to verify the result of the calculation.


14. We can link an value and use multiple couts to make an sentence.
We can directly refer to the variable to be simpler to write and
remember.

15. We don’t use quote punctuation when it is to refer variables.

16.We can write many variables and strings in only one line.

17. Cout is an output command, so cin will be an input command. It can


be used as to input an password.

18. Use << for output, and >> for input.

19.If command is used for true or false, if the value input in the code
correspond to which if value has, then the code will execute. If not, it
will not

20. If values are always followed by parenthesis.

21. Some symbols in if clauses:

 == equal to

 != not equal to

 > greater than

 < less than

 >= greater than or equal to

 <= less than or equal to

22. If the result of the input in not equal to the if clause, then we can use
else clause to make something happen after.
23.But if you want to put other if clauses you can put else if.

24. If you want to use a big number of if or else clauses, you can use the
switch function, a switch function must be followed with parenthesis
and a variable inside it.

25. The word “case” in the switch command suggests an possibility of


the value, if the value pointed is shown in the switch command, the
respective value will be connected to a case, which will after execute
a command.

26. To make an valid variable you need the following parts:

Value of variable
double pi = 3.14
The integer
The name of
variable

27.

 &&: the and logical operator

 ||: the or logical operator

 !: the not logical operator

You might also like