Found 7401 Articles for C++

match max_size() function in C++ STL

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

61 Views

The match max_size() function in C++ STL returns the maximum number of elements in the match_results object that can be held by the match container.This function does not accept a parameter.Example Code Live Demo#include #include using namespace std; int main() {    match_results m;    cout

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

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

683 Views

Set::begin() function is a bidirectional iterator used to return an iterator pointing to the first element of the set container.Set::end() function is a bidirectional iterator used to return an iterator pointing to the last element of the set container.Example Code Live Demo#include #include using namespace std; int main() {    set s;    set::iterator it;    s.insert(7);    s.insert(6);    s.insert(1);    s.insert(4);    s.insert(2);    s.insert(9);    s.insert(10);    for (auto it=s.begin(); it != s.end(); ++it)       cout

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 lower_bound() function in C++ STL

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

1K+ Views

Set lower_bound() function in C++ STL returns an iterator pointing to the element in the container which is equivalent to k passed in the parameter. If k is not present in the set container, then the function returns an iterator pointing to the immediate next element which is just greater than k.AlgorithmBegin    Initialize an empty set container s.    Initializing a set container as inetrator.    Insert some elements in s set container.    Call function to find the lower bound value of a given key, which is    passed to iter set container.    Print the lower bound ... Read More

Set find() function in C++ STL

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

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

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

693 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 memory allocations, then it is a must to have a copy constructor. The most common form of ... Read More

Structure vs class in C++

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

141 Views

In C++ the structure and class are basically the same. But there are some minor differences. These differences are like below.The class members are private by default, but members of structures are public. Let us see these two codes to see the differences.Example Code Live Demo#include using namespace std; class my_class {    int x = 10; }; int main() {    my_class my_ob;    cout

Functors in C++

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

237 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.Example Code Live Demo#include #include using namespace std; int square(int x) {    return x*x; //return square of x } int main() {    int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};    transform(data, data+10, data, square);    for (int i = 0; i

Return from void functions in C++

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

16K+ 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 returnA void function cannot return any values. But we can use the return statement. It indicates that the function is terminated. It increases the readability of code.Example Code Live Demo#include using namespace std; void my_func() {    cout

Inline Functions in C++

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

393 Views

C++ inline function is a powerful concept that is commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.Any change to an inline function could require all clients of the function to be recompiled because the compiler would need to replace all the code once again otherwise it will continue with old functionality.To inline a function, place the keyword inline before the function name and define the function before any calls are made to the function. The compiler can ... Read More

Advertisements