
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

8K+ Views
The prepended double colon (::) is also known as the scope resolution operator. The scope resolution operator serves various purposes in C++. In this article, we will discuss the applications of the scope resolution operator in C++ with example codes of each application. Uses of Scope Resolution Operator in C++ The scope resolution operator serves various purposes in C++. We have listed below 5 applications of the scope resolution operator: The scope resolution operator is used to define a function outside the class. It is used to access a global ... Read More

8K+ Views
A class in C++ has public, private and protected sections which contain the corresponding class members.The private data members cannot be accessed from outside the class. They can only be accessed by class or friend functions. All the class members are private by default.The protected members in a class are similar to private members but they can be accessed by derived classes or child classes while private members cannot.A program that demonstrates private and protected members in a class is given as follows −Example Live Demo#include using namespace std; class Base { public : int a = 8; ... Read More

19K+ Views
A class in C++ has the following access modifiers: public, private, and protected, which contain the corresponding class members. The protected members in a class are similar to private members as they cannot be accessed from outside the class, but they can be accessed by derived classes or child classes, while private members cannot. In this article, we will see various examples of how to access protected members in C++ and how it is different from private members. Accessing Protected Variable in C++ In this example, we have initialized a protected variable value in the parent class. We ... Read More

5K+ Views
An object is an instance of a class. The memory is allocated only when an object is created and not when a class is defined. How to Return an Object in C++? An object can be returned by a function using the return keyword. There is no specific technique to return an object, you can simply return it just like any other data type returning from the function. Consider the following syntax. Syntax The syntax for returning an object from the function is as follows: class_name function_name(class_name obj1) // Passing object { class_name obj2; ... Read More

17K+ Views
The lifetime of a static variable in a C++ function exists till the program executes. We can say the lifetime of a static variable is the lifetime of the program. The static variable is a variable that is declared using the static keyword. The space for the static variable is allocated only one time, and this is used for the entirety of the program. In this article, we will understand the lifetime of the static variable and the reason behind its lifetime. Why do Static Variable Exists until program execution? A static variable is initialized ... Read More

438 Views
Structures and classes are very similar in C++ except for some differences. So details about these differences are given below that help to decide when to use a class or structure in C++.Differences between Class and StructureAll the members of a class are private by default. This is different compared to structures as all the members of a structure are public by default.A program that demonstrates a class in C++ is given as follows −Example#include using namespace std; class Example { int val; }; int main() { Example obj; obj.val = 20; return 0; }This ... Read More

21K+ Views
To find the length of an array in C++, we can use various functions and approaches that we are going to discuss in this article. Finding the length of an array is a very common task and is used in looping through an array, sorting the array, finding maximum and minimum, and in many more scenarios. In this article, we have an array and our task is to find the length of the array in C++. Approaches to Find Length of Array Here is a list of approaches to find the length of an array in C++ which ... Read More

529 Views
Reference variableReference variable is an alternate name of already existed variable. It cannot be changed to refer another variable and should be initialized at the time of declaration. It cannot be NULL. The operator ‘&’ is used to declare a reference variable.The following is the syntax of reference variable.datatype variable_name; // variable declaration datatype& refer_var = variable_name; // reference variableHere, datatype − The datatype of variable like int, char, float etc.variable_name − This is the name of variable given by user.refer_var − The name of reference variable.The following is an example of reference variable.Example Live Demo#include using namespace std; int ... Read More

367 Views
The size of an object of an empty class in C++ is 1 byte as it allocates one unique address to the object in the memory. The size can not be 0, as the two objects can not have same memory allocation. In this article, we will see an example of checking the size of an object of an empty class in C++. Demonstrating Size of an Empty Class In this example, we have two C++ classes. One class is an empty class while other is not an empty class. We have printed the size of objects of both the ... Read More

11K+ Views
In the OOPs concept of C++, the parent class represents the root of the hierarchy while the derived class is inherited from the parent class. The derived class is presented using the scope resolution operator (::). The derived class is also known as the child class or subclass. What is Parent Class? The parent class is also called a base class used to design the structure of variable and function initialization based on access specifiers (private, public, and protected). Syntax Following is the syntax of parent class in C++: class ParentClass { // Access specifiers: ... Read More