Muhammad Magdi
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
Used to print something to the user screen.
cout << "Hello World!" << endl;
'endl' is used to leave a blank line.
Both:
- #include <iostream>
- using namespace std;
are essentials to be able to use the cout.
#include <iostream>
using namespace std;
Notes:
Operator | Meaning |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Integer Division |
% | Remainder after Division (Mod) |
Note that the precedence of the multiplication is higher than that of the subtraction
#include <iostream>
using namespace std;
int main() {
cout << 500 - 100 * 4 << endl;
return 0;
}
The Precedence of *, /, % is higher than that of +, -
#include <iostream>
using namespace std;
int main() {
int x = 10;
cout << x << endl;
return 0;
}
Reserves 4 bytes of memory to store integer values, calling these 4 bytes 'x' and giving 'x' an initial value = 10
int x = 10;
If we declared a variable without giving it an initial value, the compiler gives it a random initial value.
#include <iostream>
using namespace std;
int main() {
int x = 0;
cin >> x;
cout << x*x << endl;
}
Is used to take an input value and store it in a variable.
cin >> x;
We can take more than one input value using only one 'cin':
cin >> x >> y >> z;
Data Type | Description |
---|---|
int | Small integer number |
double |
Large real number |
long long | Large integer number |
string | A sequence of characters (word) |
char | A single character |
bool | Boolean number (0 or 1) |