Category: CPP

Constructors in C++

Constructors in C++ Constructor is a special member function of a class that initializes the object of the class. Constructor name is the same as class name and it doesn’t have a return type. Let’s take a simple example to understand the working of constructor. Example: How to use constructor in C++ Read the comments […]

Enumeration in C++

Enumeration in C++ Enum is a user defined data type where we specify a set of values for a variable and the variable can only take one out of a small set of possible values. We use enum keyword to define a Enumeration. enum direction {East, West, North, South}dir; Here Enumeration name is direction which […]

Structures in C++

Structures in C++ The Structure in C++ is a compound data type that contains different variables of different types. For example, you want to store Student details like student name, student roll num, student age. You have two ways to do it, one way is to create different variables for each data, but the downfall […]

OOPs Concepts in C++

OOPs Concepts in C++ Object oriented programming is a way of solving complex problems by breaking them into smaller problems using objects. Before Object Oriented Programming (commonly referred as OOP), programs were written in procedural language, they were nothing but a long list of instructions. On the other hand, the OOP is all about creating […]

this pointer in C++

this pointer in C++ The this pointer holds the address of current object, in simple words you can say that this pointer points to the current object of the class. Let’s take an example to understand this concept. C++ Example: this pointer Here you can see that we have two data members num and ch. In member function setMyValues() […]

Pointers in C++

Pointers in C++ Pointers in C++ is a variable that holds the address of another variable. They have data type just like variables, for example an integer type pointer can hold the address of an integer variable and an character type pointer can hold the address of char variable. Syntax of pointer data_type *pointer_name; How to […]

Strings in C++

Strings in C++ Strings are words that are made up of characters, hence they are known as sequence of characters. In C++ we have two ways to create and use strings: 1) By creating char arrays and treat them as string 2) By creating string object Let’s discuss these two ways of creating string first and then […]

Passing Array to Function in C++

Passing Array to Function in C++ You can pass array as an argument to a function just like you pass variables as arguments. In order to pass array to the function you just need to mention the array name during function call like this: function_name(array_name); Example: Passing arrays to a function In this example, we are passing two arrays a & b to […]

Multidimensional Arrays in C++

Multidimensional Arrays in C++ Multidimensional arrays are also known as array of arrays. The data in multidimensional array is stored in a tabular form as shown in the diagram below: A two dimensional array: int arr[2][3]; This array has total 2*3 = 6 elements. A three dimensional array: int arr[2][2][2]; This array has total 2*2*2 = […]

Arrays in C++

Arrays in C++ An array is a collection of similar items stored in contiguous memory locations. In programming, sometimes a simple variable is not enough to hold all the data. For example, lets say we want to store the marks of 500 students, having 500 different variables for this task is not feasible, we can […]