Beginners Introduction to the Syntax and Symantics of the C++ Programming Language
int, string, char,
bool keywords are used to declare variables in C++.
Variables are like your x and y
in algebra where x and y can take
any value.
In C++, conditional operators like
if(){
...
} else {
...
}
give different options for different conditions.
For instance:
if(age > 18){
std.cout << "You are grown-up now.\n";
} else {
std.cout << "You are still young.";
}
In C++, iteration operations are done using loops:
while loop:
while(){
...
}
and
for loop:
for(){
...
}
.
In C++, the arithmetic operators do exactly what you would expect:
+ means add;
- means subtract;
* means multiply;
/ means divide; and
% means moduli.
Note: Moduli means remainder after division.
Dividing 5 by 2 (5 ÷ 2) gives a remainder of 1.
Hence 5 % 2 = 1;
// are used for single line comments in C++.
/* ... */ are used for multi-line comments in C++.
Comments are just remarks (explanations) you write along side your
code for clarity purposes (help you define what you are doing);
and also for future remembrance of what a piece of code was meant for.
The compiler neither needs nor processes them.
Tip: You don't need to write out comments as you follow our demonstrations.