
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 33676 Articles for Programming

20K+ Views
Variables can be declared as constant using the const keyword or the #define preprocessor directive. Details about these are given as follows.The const keywordVariables can be declared as constants by using the “const” keyword before the datatype of the variable. The constant variables can be initialized once only. The default value of constant variables are zero.A program that demonstrates the declaration of constant variables in C using const keyword is given as follows.Example Live Demo#include int main() { const int a; const int b = 12; printf("The default value of variable a : %d", a); printf("The ... Read More

5K+ Views
In C language both the global and static variables must be initialized with constant values. This is because the values of these variables must be known before the execution starts. An error will be generated if the constant values are not provided for global and static variables.A program that demonstrates the initialization of global and static variables is given as follows.Example Live Demo#include int a = 5; static int b = 10; int main() { printf("The value of global variable a : %d", a); printf("The value of global static variable b : %d", b); return 0; }OutputThe ... 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

487 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