- 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 34489 Articles for Programming
18K+ 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
4K+ 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
866 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
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
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
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
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
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
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