The static member variable shares a common memory across all the objects created for the respective class. We need not refer to the static member variable using an object. However, it can be accessed using the class name itself.
Posted Date:- 2021-08-23 23:34:00
A copy constructor is a constructor that accepts an object of the same class as its parameter and copies its data members to the object on the left part of the assignment. It is useful when we need to construct a new object of the same class.
Example:
class A{
int x; int y;
public int color;
public A() : x(0) , y(0) {} //default (no argument) constructor
public A( const A& ) ;
};
A::A( const A & p )
{
this->x = p.x;
this->y = p.y;
this->color = p.color;
}
main()
{
A Myobj;
Myobj.color = 345;
A Anotherobj = A( Myobj ); // now Anotherobj has color = 345
}
Posted Date:- 2021-08-23 23:32:58
Class is a blueprint of a project or problem to be solved and consists of variables and methods. These are called the members of the class. We cannot access methods or variables of the class on its own unless they are declared static.
In order to access the class members and put them to use, we should create an instance of a class which is called an Object. The class has an unlimited lifetime whereas an object has a limited lifespan only.
Posted Date:- 2021-08-23 23:31:46
C++ compiler encodes the parameter types with function/method into a unique name. This process is called name mangling. The inverse process is called as demangling.
Example:
A::b(int, long) const is mangled as ‘b__C3Ail’.
For a constructor, the method name is left out.
That is A:: A(int, long) const is mangled as ‘C3Ail’.
Posted Date:- 2021-08-23 23:30:35
“Register” variable should be used whenever the variable is used. When a variable is declared with a “register” specifier, then the compiler gives CPU register for its storage to speed up the lookup of the variable.
Posted Date:- 2021-08-23 23:29:03
Storage class determines the life or scope of symbols such as variable or functions.
C++ supports the following storage classes:
Auto
Static
Extern
Register
Mutable
Posted Date:- 2021-08-23 23:28:08
In the above code, the pointer is a null pointer. Per the C++ 03 standard, it’s perfectly valid to call delete on a NULL pointer. The delete operator would take care of the NULL check internally.
Posted Date:- 2021-08-23 23:26:57
COPY CONSTRUCTOR is a technique that accepts an object of the same class and copies its data member to an object on the left part of the assignment.
Posted Date:- 2021-08-23 23:26:11
Pre-processors are the directives, which give instruction to the compiler to pre-process the information before actual compilation starts.
Posted Date:- 2021-08-23 23:25:21
Upcasting is the act of converting a sub class references or pointer into its super class reference or pointer is called upcasting.
Posted Date:- 2021-08-23 23:24:30
The problem that arises during execution of a program is referred as exceptional handling. The exceptional handling in C++ is done by three keywords.
a). Try: It identifies a block of code for which particular exceptions will be activated
b). Catch: The catch keyword indicates the catching of an exception by an exception handler at the place in a program
c). Throw: When a problem exists while running the code, the program throws an exception
Posted Date:- 2021-08-23 23:22:54
The string is actually a one-dimensional array of characters that is terminated by a null character '