A copy constructor is a type of constructor that creates a copy of another object. If we want one object to resemble another, we can use a copy constructor. If no copy constructor is written in the program, the compiler will supply its own copy constructor.The copy constructor is used to − Initialize one object […]
October 19, 2022 | C++ | No comments
C++ references allow you to give a variable a second name that you can use to read or modify the original data stored in that variable. Once a reference has been initialized with a variable, it can be referred to using either the variable name or the reference name. For instance, A variable can be […]
October 18, 2022 | C++ | No comments
Mutable data members are those whose values can be changed in runtime even if the object’s type is constant. It is the polar opposite of constant. It is sometimes necessary to modify one or more data members of a class or struct using a const function, even if you do not want the function to […]
October 16, 2022 | C++ | No comments
Const keyword define constant values that cannot change while the program is running. A const variable must be assigned a value when it is declared. If we try to change its value after it has been initialized, we will get a compilation error. Use of const keyword with different parameters: Variables Pointers Function arguments and […]
October 16, 2022 | C++ | No comments
When the static keyword is used, variable or data members or functions can no longer be changed. It is allocated for the lifetime of the program. The static keyword can be used with: Static Variables: Variables in a function, Variables in a class Static Members of Class: Class objects and Functions in a class Static Variables in […]
October 14, 2022 | C++ | No comments
Constructor: A constructor is a special member function of a class and shares the same name as of class, which means the constructor and class have the same name. The compiler calls the constructor whenever a class object is created; it allocates memory to the object and initializes class data members with default values or […]
October 13, 2022 | C++ | No comments
What is Function Overloading & why is it used? Function overloading is an object-oriented programming feature in which two or more functions have the same name but different parameters.The function overloading feature in C++ is used to improve code readability. It is used to save the programmer from having to remember multiple function names. Function […]
October 12, 2022 | C++ | No comments
What is the Inline function & why is it used? When the program executes the function call instruction, the CPU saves the memory address of the instruction that follows the function call, copies the function’s arguments to the stack, and transfers control to the specified function. This process can occasionally result in overhead in function […]
October 11, 2022 | C++ | No comments
Now, let’s look at some of the special member functions that can be defined in C++ classes. The following are the various types of Member functions: Simple functions Static functions Const functions Inline functions Friend functions Simple Member functions: These are the basic member function, which doesn’t have any special keyword like static etc. as […]
October 9, 2022 | C++ | No comments
A member function is a function that is declared as a class member. It is declared within the class in any of the visibility modes, i.e. public, private, or protected, and it has access to all the class’s data members. If the member function is defined within the class definition, it can be defined directly […]
October 9, 2022 | C++ | No comments