Server Side Programming Articles - Page 2303 of 2651

unordered_multimap reserve() function in C++ STL

Anvi Jain
Updated on 30-Jul-2019 22:30:25

164 Views

The unordered_multimap reserve() function in C++ STL sets the number of buckets in the container to the most appropriate number so that it contains at least n elements.If n is greater than the current numbers of bucket multiplied by the max_load_factor, the container’s number of buckets is increased and a rehash is forced.Reserve () returns nothing and take n as a parameter which specifies the minimum number of elements as per requested minimum capacity.AlgorithmBegin    Declare the vector m.    m.reserve(6) = the size is reserved for the bucket to contain minimum number of one elements.    Insert the key ... Read More

unordered_multimap rehash() function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

109 Views

The unordered_multimap rehash(N) function in C++ STL sets the number of buckets in the container to n or more. A rehash is forced if n is greater than the current number of buckets in the container. The new bucket count can either be equal to or greater than n. The function may have no effect on the bucket count and may not force a rehash if n is lower than the current number of buckets in the container. Rehash () returns nothing and take n as a parameter which specifies the minimum number of buckets for the container hash table.AlgorithmBegin ... Read More

STL Priority Queue for Structure or Class in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

655 Views

STL Priority Queue is the implementation of maxheap.This is a C++ program of STL priority queue for structure.AlgorithmBegin    Define a structure of type student.    Initialize variables in student structure.    Define another structure of type comparemarks    Overload the variables of student structure in comapremarks    structure.    Use priority queue with structure.    Insert some elements in priority queue using student structure.    While the queue is not empty do       Print the elements. End.Example Code Live Demo#include #include using namespace std; #define ROW 6 #define COL 3 struct student { //defining the student ... Read More

set::begin() and set::end() in C++ STL

Revathi Satya Kondra
Updated on 12-Jun-2025 14:01:51

1K+ Views

The begin() and end() functions are member functions of the std::set container, which is defined in the header file. The std::set in C++ STL (Standard Template Library) always stores its elements in sorted order. So when you use begin() and end() functions, the elements in the set, which are automatically arranged in sorted order (from smallest to largest by default) retrieve the smallest as the first element and largest as the last element. The begin() and end() functions are used to loop through all elements of the set. The std::set uses bidirectional iterators, where you can: ... Read More

Set vs Map in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

Set is an abstract data type in which each element has to be unique because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, but it is possible to remove and add the modified value of that element.A Map is an associative container that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values.So, it is clear from above that, set contains the only key, and map contains a value with ... Read More

Set find() function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

605 Views

Set find() function in C++ STL returns an iterator to the element which is searched in the set container. The iterator points to the position just after the last element in the set, if the element is not found.AlgorithmBegin    Define function printS() to print elements of set container.    initialize an empty set container s. Insert some elements in s    set container. Call function to print elements of set container.    Call the set find() function to find an element from s set container.    If element is in the set then       Print elememt is ... Read More

When is copy constructor called in C++?

Revathi Satya Kondra
Updated on 26-May-2025 16:41:09

1K+ Views

The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to Initialize one object from another of the same type. Copy an object to pass it as an argument to a function. Copy an object to return it from a function. If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer variables and has some dynamic ... Read More

Functors in C++

Revathi Satya Kondra
Updated on 26-May-2025 16:50:30

385 Views

The functors are the function objects in C++. The functor allows an instance object of some class to be called as if it were an ordinary function. Let us consider a function that takes one argument. We can use this function as function object to do some task on a set of data. The Functors are widely used in STL algorithms like transform(), sort(), etc. Functor vs Regular Function: Need of Functor? Imagine we have a function that takes only one argument, like this: int increment(int x) { return x + 1; } Now, what ... Read More

Return from void functions in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 13:16:07

18K+ Views

The void functions are called void because they do not return anything. "A void function cannot return anything" this statement is not always true. From a void function, we cannot return any values, but we can return something other than values. Some of them are like below. A void function can return A void function cannot return any values. But we can use the return statement. It indicates that the function is terminated.ExampleThe following example demonstrates a void function with the return statement: #include using namespace std; void my_func() { cout

What should we assign to a C++ pointer: A Null or 0?

Revathi Satya Kondra
Updated on 12-Jun-2025 14:25:46

1K+ Views

In C++, a pointer stores the address of another variable, which means that the pointer itself does not contain a value of its own. However, you can assign a null value or a 0 to a pointer, in which case the pointer will not point to the address of any other variable. NULL: It is special constant that indicates the pointer does not point to any valid memory location i.e., an Empty Pointer. 0: It is an older way to represent a null pointer to indicate that the pointer points to nothing. nullptr: It is introduced in C++11, it ... Read More

Advertisements