26-27 Operating system
28-29 Networking
30-1-2-3 Database
4-5-6 Oop
7-8-9 Data structure and algo
10-11-12 Artificial intelligence
13-14-15-16-17 Software engine
18-30 Islamic study
Pak study
Everyday science
Urdu
Oop concepts
bool: For booleans, true or false.
char: For characters. Size 1 byte.
int: For integers. Size 2 bytes.
float: For floating point. Size 4 bytes.
double: floating point. Size 8 bytes
Constructor is a special member function of a class that initializes the
object of the class. Constructor name is same as class name and it doesn’t
have a return type. Lets take a simple example to understand the working
of constructor.
Constructor vs Member function
Now that we know what is constructor, lets discuss how a constructor is
different from member function of the class.
1) Constructor doesn’t have a return type. Member function has a return
type.
2) Constructor is automatically called when we create the object of the
class. Member function needs to be called explicitly using object of class.
3) When we do not create any constructor in our class, C++ compiler
generates a default constructor and insert it into our code. The same does
not apply to member functions.
This is how a compiler generated default constructor looks:
Types of Constructor in C++
There are two types of constructor in C++. 1) Default constructor 2)
Parameterized constructor
1) Default Constructor
A default constructor doesn’t have any arguments (or parameters)
2) Parameterized Constructor
Constructors with parameters are known as Parameterized constructors.
These type of constructor allows us to pass arguments while object
creation. Lets see how they look: