IIn this tutorial, we will be discussing a program to understand how to delete elements in the C++ STL list.For this, we will be using the pop_back() and pop_front() function to delete the element from last and the front respectively.Example Live Demo#include #include using namespace std; int main(){ listlist1={10,15,20,25,30,35}; cout
In this tutorial, we will be discussing a program to understand how to initiate a multidimensional array in C/C++.While declaring a multidimensional array, the value of the leftmost dimension can be left empty, but all other dimensions must be provided.Example Live Demo#include int main(){ int a[][2] = {{1,2},{3,4}}; printf("%lu", sizeof(a)); getchar(); return 0; }Output16
In this tutorial, we will be discussing a program to understand extended integral types in C/C++.The data types in C are very loosely defined. Their range values changes on the basis of the compiler being 32 or 64 bit. To specify the compiler range you want to use in your program we use intN_t.Example Live Demo#include using namespace std; int main(){ uint8_t i; //mentioning the bit to be 8 i = 0; cout
In this tutorial, we will be discussing a program to find the floor and ceil of a sorted array using C++ STL.To find the floor and ceil of a sorted array we will use lower_bound() and upper_bound() functions from STL respectively.Example Live Demo#include using namespace std; //finding floor of given array void printFloor(int arr[], int n1, int findFloor[], int n2){ int low; cout findFloor[i]) cout
In this tutorial, we will be discussing a program to draw a line in C++ graphics.To implement different shapes and sizes, animations, graphics.h library is used in C++.Example#include int main(){ int gd = DETECT, gm; initgraph(&gd, &gm, ""); line(150, 150, 450, 150); line(150, 200, 450, 200); line(150, 250, 450, 250); getch(); closegraph(); return 0; }Output
In this tutorial, we will be discussing a program to understand if the C++ compiler creates a default constructor when we write our own.Generally, the C++ compiler uses the default constructor when no one is defined, but always uses the one defined by the user if any.Example Live Demo#include using namespace std; class myInteger{ private: int value; //other functions in class }; int main(){ myInteger I1; getchar(); return 0; }OutputCompiles successfullyExample#include using namespace std; class myInteger{ private: int value; public: myInteger(int v) //user-defined constructor { value = ... Read More
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; }
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP