
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++

2K+ Views
Here we will see what is the proxy class in C++. The Proxy class is basically the Proxy design pattern. In this pattern an object provides a modified interface for another class. Let us see one example.In this example, we want to make an array class, that can store only binary values [0, 1]. This is the first try.Example Codeclass BinArray { int arr[10]; int & operator[](int i) { //Put some code here } };In this code, there is no condition checking. But we want the operator[] to complain if we put something like ... Read More

26K+ Views
In C/C++, there is no special method for comparing NULL values. We can use if statements to check whether a variable is null or not.Here, we will attempt to open a file in read mode that does not exist on the system. In this case, the function will return a NULL pointer. We can check whether it is NULL or not using an if statement. C Example to Check Variable is NULL or Not In this example, we check whether the file is exist or not using NULL. #include int main() { //try to open ... Read More

2K+ Views
In C++, a map is defined by an element storage container in the form of key-value pairs where each key is unique and mapped with a respective value. While range-based for loop is a very simple approach to iterate over elements in the container. In this article, we will learn the usage of range-based for loop over std::map in C++. Example Scenario Input: myMap: { {1, "Ravi"}, {2, "Tom"} } Output: 1: Ravi 2: Tom What is std::map? The std::map is an associative container that stores key-value pairs in sorted order. The maps are used for fast lookup, insertion, and deletion based on keys.Following is the basic ... Read More

4K+ Views
Why do we need message queues when we already have the shared memory? It would be for multiple reasons, let us try to break this into multiple points for simplification −As understood, once the message is received by a process it would be no longer available for any other process. Whereas in shared memory, the data is available for multiple processes to access.If we want to communicate with small message formats.Shared memory data need to be protected with synchronization when multiple processes communicating at the same time.Frequency of writing and reading using the shared memory is high, then it would ... Read More

4K+ Views
Shared memory is a memory shared between two or more processes. However, why do we need to share memory or some other means of communication?To reiterate, each process has its own address space, if any process wants to communicate with some information from its own address space to other processes, then it is only possible with IPC (inter process communication) techniques. As we are already aware, communication can be between related or unrelated processes.Usually, inter-related process communication is performed using Pipes or Named Pipes. Unrelated processes (say one process running in one terminal and another process in another terminal) communication ... Read More

954 Views
In C++, the size of the floating point number is either 4-byte or 8-bytes. So it can store up to few decimal places. For example, the 1/3 = 0.333333…… Up to infinity. If we store it inside floating type variable, then it will store some significant digits. The default value is 6. So normally floating point numbers in C++ can display up to 6 decimal places.We can change the size of the precision using setprecision. This is present inside the iomanip header file. Let us see one example to get the idea.Example Code#include #include using namespace std; int ... Read More

512 Views
Here we will see some good features and tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes. Let us see some of these examples one by one.Checking whether a number is odd or even without using % operator. This trick is simple. We can perform bitwise AND operation with the number and 1. If the result is non-zero then this is odd, otherwise this is even. The logic is too simple. All odd ... Read More

3K+ Views
In C++, we can use the inline keyword for functions. In C++ 17 version, the inline variable concept has come.The inline variable is allowed to be defined in multiple translation units. It also follows the one definition rule. If this is defined more than one time, the compiler merges them all into a single object in final program.In C++ (before C++17 version), we cannot initialize the value of static variables directly in the class. We have to define them outside of the class.Example Code#include using namespace std; class MyClass { public: MyClass() { ... Read More

16K+ Views
When working with floating-point numbers in C++, it's important to know how to control the number of decimal places displayed in the output. By default, cout may not always print the expected number of digits after the decimal point.How to Print Correct Number of Decimal Points with cout?To display numbers with a specific number of decimal places using cout, you can use the setprecision() function, which accepts an integer value representing the number of digits after the decimal to be printed and returns a stream manipulator that formats the number with the specified precision. The setprecision() function belongs to the ... Read More

17K+ Views
C++ has no direct method to check one object is an instance of some class type or not. In Java, we can get this kind of facility.In C++11, we can find one item called is_base_of. This will check if the given class is a base of the given object or not. But, this does not verify whether the given class instance uses that function. The nearest possible functionality similar to "instanceof" can be achieved using dynamic_cast (expression). This tries to covert the given value into the specified type and returns the result. if the cast is unsuccessful this returns a null ... Read More