C Plus Plus Cheat Sheet
C Plus Plus Cheat Sheet
What is C++?
Data Types
Set of values together with set of operations called data type.C++ data types
classified into three categories:
1.Simple data type
2.Structured data type
3.Pointers
I. char
II. short
III. int
IV. long
V. bool
VI. unsigned char
VII. unsigned short
VIII. unsigned int
IX. unsigned long
Floating-Point Data Types :
I. float
II. double
III. long double
Standard Library
Type Description
bool Stores either value true or false.
Typically a single octet(one byte). This is an integer
char type.
int The most natural size of integer for the machine.
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
Operators in C++
I. Arithmetic Operators
II. Relational Operators
III. Logical Operators
IV. Bitwise Operators
V. Assignment Operators
VI. Misc Operators
1.Arithmetic Operators.
Operator Description Example
+ Adds two operands X + Y = 20
Subtracts second operand
from the first XY=8
* Multiplies both operands X * Y = 84
Divides numerator by de-
/ numerator X/Y=2
Modulus Operator and
remainder of after an integer
% division Y % X= 0
Increment operator, increases
++ integer value by one X++ = 15
Decrement operator, decreases
integer value by one X = 13
II.Relational Operators
Operator Description Example
Checks if the values of two operands are equal or (X == Y) is
== not. If yes, then the condition becomes true. not true.
Checks if the values of two operands are equal or
not. If the values are not equal, then the (X != Y) is
!= condition becomes true. true.
Checks if the value of left operand is greater than
the value of right operand. If yes, then the (X > Y) is
> condition becomes true. not true.
Checks if the value of left operand is less than
the value of right operand. If yes, then the (X < Y) is
< condition becomes true. true.
Checks if the value of left operand is greater than
or equal to the value of right operand. If yes, (X >= Y) is
>= then the condition becomes true. not true.
Checks if the value of left operand is less than or
equal to the value of right operand. If yes, then (X <= Y) is
<= the condition becomes true. true
III.Logical Operators
V.Assignment Operators
VI.Misc Operators
Use iostream to extract (receive) data from keyboard and send output
to the screen
IOstream contains definitions of two types:
To use cin and cout, the preprocessor directive #include <iostream> must be
used
The declaration is similar to the following C++ statements:
1. istream cin;
2. ostream cout;
Input stream variables: type istream
FUNCTIONS
What are Functions?
A function is a group of statements that together perform a task.
Every C program has at least onefunction, which is main(), and all the most
trivial programs can define additional functions. You can divide up your
code into separate functions.
Predefined and User-Defined Functions
1) Predefined standard library functions These are available to anyone
who writes a C++ program. This saves the programmers time from writing
own functions. They are completely debugged, efficient and always produce
a precise output. The important contribution of the system-supplied
functions is that they provide clarity to the program because they do not
have to be redefined. It reduces the source code, which saves time of the
programmer.
2) User Defined functions C++ language allows additional functions
besides the built-in functions called the user-defined function. It allows
programmers to define their own functions. The programmer must code the
logic of this type. In order to do so, a declaration is needed.
Enumeration Data Type
Concept Description
C++ supports multidimensional arrays. The
simplest form of the multidimensional array
Multi-dimensional arrays is the two-dimensional array.
You can generate a pointer to the first
element of an array by simply specifying the
Pointer to an array array name, without any index.
You can pass to the function a pointer to an
array by specifying the arrays name
Passing arrays to functions without an index.
Return array from functions C++ allows a function to return an array.
Structures
Once you declare a structure person as above. You can define a structure
variable as:
How to define a structure variable?
Strings
The standard C++ library provides a string class type that supports all the
operations mentioned above, additionally much more functionality. We will
study this class in C++ Standard Library
Pointers
There are few important operations, which we will do with the pointers very
frequently. (x) we define a pointer variables (y) assign the address of a
variable to a pointer and (z) finally access the value at the address available
in the pointer variable. This is done by using unary operator * that returns
the value of the variable located at the address specified by its operand.
C++ Pointers in Detail
Concept Description
C++ supports null pointer, which is a
constant with a value of zero defined in
C++ Null Pointers several standard libraries.
There are four arithmetic operators that can
C++ pointer arithmetic be used on pointers: ++, , +,
There is a close relationship between
C++ pointers vs arrays pointers and arrays. Let us check how?
You can define arrays to hold a number of
C++ array of pointers pointers.
C++ allows you to have pointer on a pointer
C++ pointer to pointer and so on.
Passing an argument by reference or by
address both enable the passed argument
Passing pointers to to be changed in the calling function by the
functions called function.
C++ allows a function to return a pointer to
Return pointer from local variable, static variable and
functions dynamically allocated memory as well.
Inheritance
Types of Inheritance:
1. Single Inheritance.
2. Multilevel Inheritance.
3. Multiple Inheritance.
4. Hierarchical Inheritance.
5. Hybrid Inheritance.
Polymorphism
Polymorphism is one of the crucial feature of c++ it simply means one name
and multiple forms.The function overloading and operator overloading is
known as compile time Polymorphism / static Polymorphism.
Data Abstraction
Data Encapsulation