Found 7347 Articles for C++

Copysign() function in C++

Sunidhi Bansal
Updated on 20-Jan-2020 07:27:50

60 Views

Given the task is to show the working of copysign() in C++.The copysign() function is a part of the C++ standard template library. It takes two arguments and produces the result by combining the magnitude of the first value and the sign of the second value. or header file should be included to call this function.SyntaxThe syntax is as follows −copysign(x, y)ExampleInput: copysign(4, -5) Output: -4Explanation − The following example demonstrates how we can copy the sign of one value to the magnitude of another value. The sign of the second argument, that is “-“and the magnitude of the ... Read More

list emplace() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:26:29

491 Views

Given is the task to show the working of list emplace() function in C++.The list::emplace() function is a part of the C++ standard template library. It is used to insert values inside a list at a specified position by the user. header file should be included to call this function.SyntaxList_Name.emplace(position, element)ParametersThis function takes two parameters −First is position, which represents the position at which the new element has to be placed and the second is value, which represents the element that has to be inserted inside the list at the position.Return ValueThe function returns an iterator that point at the ... Read More

List assign() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:22:18

2K+ Views

Given is th e task to show the working of the assign() function in C++.The list::assign() function is a part of the C++ standard template library. It is used to assign the values to a list and also to copy values from one list to another. header file should be included to call this function.SyntaxThe syntax for assigning new values is as follows −List_Name.assign(size, value)SyntaxThe syntax for copying values from one list to another is as follows −First_List.assign(Second_List.begin(), Second_list.end())ParametersThe function takes two parameters −First is size, that represents the size of the list and the second one is value, which ... Read More

List crbegin() and crend() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:20:41

73 Views

Given is the task to show the working of list crbegin() and crend() functions in C++.The list::crbegin() and list::crend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::crbegin()This function returns the constant iterator which points to the end element of the list which will be the reverse beginning of the list. It can be used for Backtracking the list but it cannot change the values in the list which means crbegin() function can be used for iteration only.SyntaxList_Name.crbegin()ParametersThe function does not accept any parameter.Return ValueThe function returns a constant reverse ... Read More

list cbegin() and cend() functions in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:19:07

80 Views

Given is the task to show the working of list::cbegin() and list::cend functions in C++.The list::cbegin() and list::cend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::cbegin()This function returns the constant iterator which points to the beginning element of the list. It can be used to traverse the list but it cannot change the values in the list which means cbegin() function can be used for iteration only.SyntaxList_Name.cbegin();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that point at the beginning element of the list.list::cend()This function ... Read More

list back() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:15:40

154 Views

Given is the task to show the working of list back() function in c++.The list::back() function is a part of the C++ standard template library. It is used to display the last element of any list. header file should be included before calling this function.SyntaxList_Name.back();ParametersThe function does not accept any parameter.Return ValueThe function returns the value of the last element of the list.ExampleInput: Lt.assign(3, 10) Lt.back() Output: 10Explanation − The following example shows how we can find the last value of any list by using the back() function. The list Lt is assigned three elements, each with value 10 and ... Read More

deque assign() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:14:55

198 Views

Given the task is to show the working of deque::assign() in C++ STL.Deque is a double ended queue. In C++, deque::assign() is an inbuilt function which is used to assign the new value to the deque container. Every time this function is called it assigns a new value to the deque container by replacing the existing values and changing the size allocated accordingly.SyntaxSyntax of deque::assign() is as follows −dequename.assign( size, val)ParametersThis function includes 2 parameters −First is the size, which represents the size of the deque container and the second one is val, which is the value contained by ... Read More

strstr() function in C/C++

Sunidhi Bansal
Updated on 20-Jan-2020 07:10:22

555 Views

strstr() function is a predefined function in “string.h” header file which is used for performing string handling. This function is used to find the first occurrence of a substring let’s say str2 in the main string let’s say str1.SyntaxSyntax of strstr() is as follows −char *strstr( char *str1, char *str2);Parameters of strstr() arestr2 is the substring which we wish to search in the main string str1Return value of strstr() isThis function returns the address pointer of the first occurrence of the substring which we are searching if found in the main string, else it will return a null when the ... Read More

Find N Unique Integers Sum up to Zero in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:38:05

248 Views

Suppose we have an integer n. We have to return any array that contains n unique integers, such that they add up to 0. So if input is n = 5, then one possible output will be [-7, -1, 1, 3, 4]To solve this, we will follow these steps −take an array A as final answer, and take x := 0for i in range 0 to n – 2A[i] = (i + 1)x := x + i + 1A[n – 1] = xreturn AExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Replace Elements with Greatest Element on Right Side in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:28:08

328 Views

Suppose we have an array A. We have to replace every element by the greatest element on the right side of this element. And replace the last one by -1. So if A = [5, 17, 40, 6, 3, 8, 2], then it will be [40,40,8,8,8,2,-1]To solve this, we will follow these steps −We will read the array element from right to left.take e := -1for i := n – 1 to 0temp := ee := max between e and array[i]array[i] := tempreturn arrayExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Advertisements