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
C++ Articles - Page 674 of 719
569 Views
Static C++ class members can be defined using the static keyword. The static member in a class is shared by all the class objects as there is only one copy of the static class member in the memory, regardless of the number of objects of the class.The static class member is initialized to zero when the first object of the class is created if it is not initialized in any other way.A program that demonstrates static class members in C++ is given as follows.Example Live Demo#include using namespace std; class Example { public : static int a; ... Read More
2K+ Views
In C/C++, a variable name can have alphabets, numbers, and the underscore( _ ) character. There are some keywords in the C/C++ language. Apart from them, everything is treated as an identifier. Identifiers are the names of variables, constants, functions, etc. Why Variables in C/C++ Can't Start with Numbers? In C and C++, variable names (also, known as identifiers) cannot start with a digit due to how the compiler processes code during compilation. First, we need to understand the phases of compilation or compiler. There are seven phases in a typical compiler: Lexical Analysis ... Read More
1K+ Views
You can call a class member function using a NULL object pointer in C++. This is an undefined behavior and there is no guarantee about the execution of the program. The actual results depend on the compiler used. Class Member Function A class member function is a function that is defined either inside a class or outside a class using a scope resolution operator. Example Here is an example of class member functions in C++ where the print() function is an example of the Inside class function and the print2() function is ... Read More
18K+ Views
An array is a fixed-size collection of elements of the same data type that stores data in contiguous memory locations. Initializing an array with one default value in C++ is an easy task and can be easily implemented using various approaches that we are going to understand with code examples. Initializing Array with Zeroes in C++ To initialize all elements of an array with 0, we will simply initialize the array with 0 or just use empty curly braces. Example Here is an example that uses the above mentioned methods to initialize the array with 0: #include using ... Read More
3K+ Views
The fastest algorithm to find the prime numbers is the Sieve of Eratosthenes algorithm. It is one of the most efficient ways to find the prime numbers smaller than n when n is smaller than around 10 million. In this article, we have a given number as 'num'. Our task is to find all the prime numbers less than or equal to num using Sieve of Eratosthenes algorithm in C++. Example Here is an example to find prime numbers less than 10: Input: num = 10 Output: 2 3 5 7 The explanation of the above ... Read More
494 Views
A class method can be can be called using a NULL class pointer.Note − This is undefined behaviour and there is not guarantee about the execution of the program. The actual results depend on the compiler used.A program that demonstrates this is given as follows.Example Live Demo#include using namespace std; class Example { public : void func() { cout func(); return 0; }OutputThe output of the above program is as follows.The function is called through Null class pointer.Now, let us understand the above program.The class Example contains a member function func(). This function displays ... Read More
2K+ Views
The main() function can call itself in C++. This is an example of recursion, i.e., a function calling itself. In recursion, a function calls itself over and over again with modified arguments until it reaches its base case or the termination condition, where the recursion stops. In this article, we will go through three C++ examples where the main function calls itself. Counting Numbers up to N To count numbers up to 'n', we will recursively call the main function until it reaches 'n'. Example The following example calls the main() function recursively to print the numbers from 1 ... Read More
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