C++ Articles - Page 601 of 719

Bidirectional Iterators in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

468 Views

Here we will see the concept of Bidirectional iterators in C++.The bidirectional iterators support all of the features of forward iterators, and also prefix and postfix decrement operators.This type of iterator can access elements in both directions, like towards the end and towards the beginning.The random access iterator is also a type of bidirectional iterator.Bidirectional iterators have features of forward iterator, but only difference is this iterator can also be decremented.The Bidirectional iterators has some properties. These are like below.PropertyExpressionThe bidirectional iterator is default-constructible, copy-assignable, and also destructibleA pA q(p) q = pWe can compare them using equality and inequality operatorsp ... Read More

Output Iterators in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

749 Views

Here we will see what are the Output iterators in C++. The Output iterators has some properties. These are like below:The output iterators are used to modify the value of the containers.We cannot read data from container using this kind of iteratorsThis is One-Way and Write only iteratorIt can be incremented, but cannot be decremented.There are two sub-parts of Output iterators. These are Insert Iterator and ostream iterator.The Insert IteratorThe insert iterator is used to insert some element inside the container. The assignment operator on this type of iterator inserts new element at current position. The syntax of insert iterator ... Read More

Composite Design Pattern in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

1K+ Views

Composite pattern is used where we need to treat a group of objects in similar way as a single object. Composite pattern composes objects in term of a tree structure to represent part as well as whole hierarchy. This type of design pattern comes under structural pattern as this pattern creates a tree structure of group of objects.This pattern creates a class that contains group of its own objects. This class provides ways to modify its group of same objects.We are demonstrating use of composite pattern via following example in which we will show employees hierarchy of an organization.Here we ... Read More

Iterator Invalidation in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

1K+ Views

In C++, we have different containers like vector, list, set, map etc. To iterate through these containers, we can use the iterators. We should be careful when we are using iterators in C++. When we are using iterating over a container, then sometimes, it may be invalidated. If the shape, size is changed, then we can face this kind of problems. In the following example, we can identify the problem of invalidation.Example Code#include #include using namespace std; int main() {    vector vec{11, 55, 110, 155, 220};    for (auto it=vec.begin(); it!=vec.end(); it++)       if ... Read More

I/O Redirection in C++

George John
Updated on 30-Jul-2019 22:30:26

749 Views

In C, we can use the freopen() function for redirection purposes. Using this function, we can redirect existing FILE pointer to another stream. The syntax of the freopen is like below:FILE *freopen(const char* filename, const char* mode, FILE *stream)In C++ also, we can do the redirection. In C++, the streams are used. Here we can use our own stream, and also redirect system streams. In C++, there are three types of streams.istream : Stream, that can support input onlyostream : Stream, that can support output onlyiostream : These can be used for input and output.These classes, and file stream classes ... Read More

Floating Point Operations and Associativity in C, C++ and Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

304 Views

In C, C++, and java, we do some mathematical operations with floating point numbers. Now here we will check whether the floating point numbers are following the associativity rule or not.The answer is NO. The floating point numbers does not follow the associativity rules in some cases. Here we will see some examples.Example Code#include using namespace std; main() {    float x = -500000000;    float y = 500000000;    float z = 1;    cout

Undefined Behaviour in C and C++

Tapas Kumar Ghosh
Updated on 16-Jun-2025 16:53:18

399 Views

In C/C++, undefined behavior refers to unexpected program output. When we write any program based on C or C++, sometimes we do not get the output as expected. This may be due to undefined behavior which cannot be predictable. For reference, sometimes it will show correct result, sometimes it will give the wrong result, and sometimes it may crash. Common Examples of Undefined Behavior in C/C++ Now, we have list of example that shows undefined behavior in C/C++ programs: Divide by Zero Using Uninitialized Variable NULL Pointer ... Read More

What do you mean by a dynamic initialization of variables?

Tapas Kumar Ghosh
Updated on 01-Jul-2025 15:08:26

8K+ Views

Dynamic initialization of object refers to initializing the objects at run time i.e., the initial value of an object is to be provided during runtime. Dynamic initialization can be achieved using constructors and passing parameters values to the constructors. This type of initialization is required to initialize the class variables during runtime. Why do we need the dynamic initialization? Dynamic initialization of objects is useful because It utilizes memory efficiently. Various initialization formats can be provided using overloaded constructors. It has the flexibility of using different formats ... Read More

How to create timer using C++11?

Tapas Kumar Ghosh
Updated on 16-Jun-2025 17:01:42

2K+ Views

The term "timer" is used to define the time based operations on hours, minutes, and seconds. Here, we can use the chrono library of C++ that helps to set the different timer operations like countdown, delayed, current time, etc. In this article, we will learn how to create a timer using C++. Timer Properties There are various properties to consider for building a timer in C++ program: Integer: int (milliseconds to wait until to run code). Boolean: bool (If this is true, it returns instantly, and run the code after specified ... Read More

What is Proxy Class in C++?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

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

Advertisements