- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7346 Articles for C++
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
In C/C++, a variable name can have alphabets, numbers and underscore( _ ) character. There are some keywords in C/C++ language, apart from them everything is treated as identifier. Identifiers are the name of variable, constants, functions etc.We can not specify the identifier which starts with a number because there are seven phases of compiler as follows.Lexical AnalysisSyntax AnalysisSemantic AnalysisIntermediate Code GenerationCode OptimizationCode GenerationSymbol TableNone of above supports that a variable starts with a number. This is because the compiler gets confused if is a number or identifier until it reaches an alphabet after the numbers. So the compiler will ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
863 Views
A class member function can be called using a NULL object pointer.Note − This is undefined behaviour and there is no 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 Demo { public : void fun() { cout fun(); return 0; }OutputThe output of the above program is as follows.This member function is called through Null object pointer.Now, let us understand the above program.The class Demo contains a member function fun(). This function displays ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
15K+ Views
The entire array can be initialized to zero very simply. This is shown below.int arr[10] = {0};However, it is not possible to initialize the entire array to a non-zero value using the above method. This is shown below.int arr[10] = {5};In the above example, only the first element will be initialized to 5. All others are initialized to 0.A for loop can be used to initialize an array with one default value that is not zero. This is shown below.for(i = 0; i
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
3K+ Views
The Sieve of Eratosthenes is one of the most efficient ways to find the prime numbers smaller than n when n is smaller than around 10 million.A program that demonstrates the Sieve of Eratosthenes is given as follows.Example#include using namespace std; void SieveOfEratosthenes(int num) { bool pno[num+1]; memset(pno, true, sizeof(pno)); for (int i = 2; i*i< = num; i++) { if (pno[i] == true) { for (int j = i*2; j< = num; j + = i) pno[j] = false; } } for (int i = 2; i< = num; i++) if (pno[i]) cout
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
361 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
6K+ Views
The prepended double colon is also known as the scope resolution operator. Some of the uses of this operator are given as follows.Define a function outside a classThe scope resolution operator can be used to define a function outside a class. A program that demonstrates this is given as follows.Example Live Demo#include using namespace std; class Example { int num; public: Example() { num = 10; } void display(); }; void Example::display() { cout
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
17K+ Views
A class in C++ has public, private and protected sections which contain the corresponding class members. 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.A program that demonstrates accessing protected data members in a derived class in C++ is given as follows −Example Live Demo#include using namespace std; class Base { protected : int num = 7; }; class Derived : public Base { public : void func() { cout
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
4K+ Views
An object is an instance of a class. Memory is only allocated when an object is created and not when a class is defined.An object can be returned by a function using the return keyword. A program that demonstrates this is given as follows −Example Live Demo#include using namespace std; class Point { private: int x; int y; public: Point(int x1 = 0, int y1 = 0) { x = x1; y = y1; } Point addPoint(Point p) { Point temp; temp.x = x + p.x; temp.y = y + p.y; return temp; } void display() { cout