C++ CHeat Sheet
Special Characters Operators Arithmetic Operations
// used to start a comment < less than x++ increments by one
() used in a method header to mark > greater than x-- decreases by one
parameters ==equal to x/y divide
{} encloses a group of statements .equals(for Strings) x*y multiply
““ encloses string of characters <= less than or equal to x+y additon
; marks the end of a statement >= greater than or equal to x-y subtraction
&& and x%y finding the remainder
C++ Escape Sequences || or sqrt() square root
\n newline ! not pow() power
\t tab
\b backspace Vectors
\r carriage return Random Initialization:
\\ backslash #include <time.h> Vector <datatype> Vectorname;
\’ single quote srand(time(NULL));
\” double quote rand()%(number); Operations:
vector.push_back;
Data Types Arrays vector.pop_back;
byte = -128 to 127 Initiating an array: vector.insert();
short = -32768 to 32767 int array [10];
int = -2147483648 to 2147483647 Printing an array: Printing an Vector:
long = huge number ranges for(int i = 0;
float holds decimals with 7 digits i<sizeof(array)/sizeof(array[0]);i++) for(int i = 0; i<vector.size();i++)
of accuracy { {
double holds decimals with cout<<array[i] cout<<vector[i];
15 digits of accuracy } }
Swapping:
int swap = array[i]; Printing and User Input
While Loops array[i] = array[x]; #include <iostream>
while (condition) array[x] = swap; using namespace std;
{
statement; cout<<”text”;
} int x;
cin>>x;
For Loops (pre check)
for( int i = 0; i<number; i++)
{
statement;
}
Do Loops(post check)
do{
statement;
}while(condition)