General
C++ is a programming language, used for computers. C++ is created by a Bjarne Stroustrup, from denmark. C++ is a better version of C (C programming language). C++ have classes which C dosen't have.
Variables
Name | Description | Size* | Range* |
---|---|---|---|
char | Character or small integer. | 1byte | signed: -128 to 127 unsigned: 0 to 255 |
short int (short ) | Short Integer. | 2bytes | signed: -32768 to 32767 unsigned: 0 to 65535 |
int | Integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
long int (long ) | Long integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
bool | Boolean value. It can take one of two values: true or false. | 1byte | true or false |
float | Floating point number. | 4bytes | +/- 3.4e +/- 38 (~7 digits) |
double | Double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
long double | Long double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
wchar_t | Wide character. | 2 or 4 bytes | 1 wide character |
Strings
Variables that can store non-numerical values that are longer than one single character are known as strings.
The C++ language library provides support for strings through the standard string class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.
A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code: <string> and have access to the std namespace.
If, Else
If, Else
The if statement says that if that equals true then do something, if not then do something else. Like this:
#include <iostream>
#include "conio.h"
using namespace std;
int main() { // define two integers int x = 3; int y = 4;
//print out a message telling which is bigger if (x > y) { cout << "x is bigger than y" << endl;
_getch(); } else { cout << "x is smaller than y" << endl;
_getch(); } }