Found 7197 Articles for C++

Delete and free() in C++ Program

Ayush Gupta
Updated on 23-Mar-2020 08:24:21

155 Views

In this tutorial, we will be discussing a program to understand delete() and free() functions in C++.Both of these functions are primarily used for the same purpose i.e freeing up unused memory. The delete() operator is for the ones allocated using new() and free() for the ones allocated using malloc().Example#include #include int main(){    int x;    int *ptr1 = &x;    int *ptr2 = (int *)malloc(sizeof(int));    int *ptr3 = new int;    int *ptr4 = NULL;    //incorrect usage of delete    delete ptr1;    delete ptr2;    //correct usage of delete    delete ptr3;    delete ptr4;    getchar();    return 0; }

Different methods to reverse a string in C/C++

Ayush Gupta
Updated on 23-Mar-2020 08:22:23

3K+ Views

In this tutorial, we will be discussing a program to understand different methods to reverse a string in C/C++.ExampleUser-defined reverse() function − Live Demo#include using namespace std; //function to reverse given string void reverse_str(string& str){    int n = str.length();    for (int i = 0; i < n / 2; i++)       swap(str[i], str[n - i - 1]); } int main(){    string str = "tutorialspoint";    reverse_str(str);    cout

Default Arguments in C++

Ayush Gupta
Updated on 23-Mar-2020 08:18:52

1K+ Views

In this tutorial, we will be discussing a program to understand default arguments in C++.Default arguments are those which are provided to the called function in case the caller statement does provide any value for them.Example Live Demo#include using namespace std; //function defined with default arguments int sum(int x, int y, int z=0, int w=0){    return (x + y + z + w); } int main(){    cout

Customizing termination behavior for uncaught exception In C++

Ayush Gupta
Updated on 23-Mar-2020 08:17:02

325 Views

In this tutorial, we will be discussing a program to customize behavior for an uncaught exceptions in C++.Usually, the exception is handled by the try-catch block, but there are instances where there isn’t a matching catch block and the program just terminates. This terminate() function is modifiable as per user requirements.Example Live Demo#include #include using namespace std; //defining custom terminator void myhandler(){    cout

is_reference Template in C++

Sunidhi Bansal
Updated on 23-Mar-2020 07:59:22

105 Views

In this article we will be discussing the working, syntax and examples of std::is_reference template in C++ STL.is_reference is a template which comes under header file. This template is used to check whether the given type T is a reference type or not.This template is a combination of is_rvalue and is_lvalue and checks whether either if one is true, the result of is_reference will be also true.What is a reference in C++?A reference is an alias or another name of the already existing variable. A reference is different from pointer −As we cannot set a reference as null but ... Read More

is_polymorphic template in C++

Sunidhi Bansal
Updated on 23-Mar-2020 07:55:52

88 Views

In this article we will be discussing the working, syntax and examples of std::is_polymorphic template in C++ STL.is_polymorphic is a template that comes under the header file in C++. This template is used to check whether the class is a polymorphic class or not and return the result either true or false accordingly.What is a polymorphic class?A class which declares the virtual function from an abstract class where the virtual function is declared. This class have the declaration of the virtual function declared in other class.Syntaxtemplate is_polymorphic;ParametersThe template can have only parameter of type T, and check whether ... Read More

is_trivial function in C++

Sunidhi Bansal
Updated on 23-Mar-2020 07:50:08

185 Views

In this article we will be discussing the working, syntax and examples of std::is_trivial template in C++ STL.is_trivial is a template which comes under header file. This template is used to check whether the given type T is a trivial class or notWhat is a trivial class type in C++?We say a type as a Trivial type, when its data is stored in a contiguous manner and which accepts only static default initialization. It can include arrays of any type, classes and scalar type.Trivial class is a class which is trivially default constructed and trivially copyable. There are some ... Read More

is_scalar template in C++

Sunidhi Bansal
Updated on 23-Mar-2020 07:47:17

206 Views

In this article we will be discussing the working, syntax and examples of std::is_scalar template in C++ STL.is_scalar is a template which comes under header file. This template is used to check whether the given type T is a scalar type or notThis template is a combination of is_arithmetic, is_pointer, is_enum, is_member_pointer or is_same and checks whether either if either one is true, the result of is_scalar will also be true.What is a scalar type in C++?A scalar type is that object which is neither a class type nor an array type. A scalar type is a type which ... Read More

multiset empty() function in C++ STL

Sunidhi Bansal
Updated on 23-Mar-2020 07:44:21

165 Views

In this article we will be discussing the working, syntax and examples of multiset::empty() function in C++ STL.What is a multiset in C++ STL?Multisets are the containers similar to the set container, meaning they store the values in the form of keys same as a set, in a specific order.In multiset the values are identified as keys as same as sets. The main difference between multiset and set is that the set has distinct keys, meaning no two keys are the same, in multiset there can be the same keys value.Multiset keys are used to implement binary search trees.What is ... Read More

multiset count() function in C++ STL

Sunidhi Bansal
Updated on 23-Mar-2020 07:40:12

868 Views

In this article we will be discussing the working, syntax and examples of multiset::count() function in C++ STL.What is a multiset in C++ STL?Multisets are the containers similar to the set container, meaning they store the values in the form of keys same like a set, in a specific order.In multiset the values are identified as keys as same as sets. The main difference between multiset and set is that the set has distinct keys, meaning no two keys are the same, in multiset there can be the same keys value.Multiset keys are used to implement binary search trees.What is ... Read More

Advertisements