Unions in C++

In a C++ programming language, union is a special user defined data type that allows to store different data types in the same memory location. “union”  uses the same memory location for multiple-purpose.  Or In a union data type, single variable, i.e., same memory location, can be used to store multiple types of data. In a … Read more

Categories C++

Local and Nested Classes in C++

In a C++ language we can define a class within a function and such classes are called local classes. Local Classes in C++ Inside the local class, we can access the global and static variables. Local class can’t access the normal/nonstatic variable of a function.

Output

Description: In the above program, class B … Read more

Categories C++

Constructor in C++

Constructor is similar to function that has a same name as the class in which it is resides . Constructor  is automatically called when the object of that class created in which it is resides. A class can contains more than one constructor. Constructor does not have a return value. Characteristics of constructor Constructor has … Read more

Categories C++

Inheritance and types of Inheritance in C++

Inheritance is a one of the most important feature of object oriented programming. Inheritance allow an object of one class to acquire the properties of another object of another class. It supports the reusability and support hierarchical classification.  The class which inherits the another class is called derived class and the class which inherited is … Read more

Categories C++

C++ program for student details using array of objects

Array of Objects in C++ Array of Object is similar to creating array or integer, character or any primitive data types. Example Array of integer is int age[5]={1,2,3,4,5}; Similar way array of Students is Student s[5]={studentObj1,studentObj2,studnetObj3,studentObj4,studentObj5}; The student is class Name s is an array of objects of 5 elements To initialize the student object … Read more

Categories C++

Size of the Object in C++

In a C++ programming language,  size of any object is equal to the sum of size of all the data members of the class. In a below program,  class contain three data type and three variable.  Data type int occupies 4 bytes, float occupies 4 bytes, and char occupies 1 byte. their sum is  9 … Read more

Categories C++

Anonymous Object in C++

Anonymous Object is a Object without any name. In C++ programming an object is created with names but It is still possible to create objects without names such objects are known as anonymous objects. When the constructor and destructor are called, the data members are initialized and destroyed respectively. Without an object, we can initialize … Read more

Local object and global object in C++

In C++ objects can be classified as local object and global object. Local object A object defined inside a block is called local object. A local object can be inside block or function or class In above figure variable a and b are local variable inside complex class. Inside main function Complex c=Complex(1,2); is defined … Read more

Categories C++

Friend Function in C++

In a C++ programming language private member of the class can accessed by member function. Any non-member function can’t access private data member of the class. But if we want to access the private data in non member function it is still possible by using the “friend function”. A friend function can access private data … Read more

Categories C++

Functions in C++

In a C++ programming language a function is a group of statements that together perform a special task. Every C++ program has at least one function, which is main(). In a C++ library has a numerous predefined or built-in functions. For example, strcat() to concatenate two strings, main() from where program execution starts.  In a C++  programming function … Read more

Categories C++