- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
133 Views
Suppose we have a binary tree; we have to flatten it into linked list in place. So if the tree is like −The output tree will be −To solve this, we will follow these steps −ser prev := nullDefine a recursive function solve(), that will take root as input.if root is null, then returnsolve(right of root)solve(left of root)right of root := prev, left of root := nullprev := rootLet us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class TreeNode{ public: int val; TreeNode *left, *right; TreeNode(int data){ ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
2K+ Views
In this tutorial, we will be discussing a program to understand thread functions in C/C++.Thread functions allow users to implement concurrent functions at the same time, which can either be dependent on each other for execution or independent.Example#include #include #include void* func(void* arg){ //detaching the current thread pthread_detach(pthread_self()); printf("Inside the thread"); pthread_exit(NULL); } void fun(){ pthread_t ptid; //creating a new thread pthread_create(&ptid, NULL, &func, NULL); printf("This line may be printed before thread terminates"); if(pthread_equal(ptid, pthread_self()) printf("Threads are equal"); else printf("Threads are ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
410 Views
In this tutorial, we will be discussing a program to understand templates and static variables in C++.In case of function and class templates, each instance of the templates has its own local copy of the variables.Example Live Demo#include using namespace std; template void fun(const T& x){ static int i = 10; cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
131 Views
In this tutorial, we will be discussing a program to understand Template specialization in C++.Standard functions like sort() can be used with any data types and they behave the same with each of them. But if you want to set a special behaviour of the function for a particular data type (even user defined), we can use template specialization.Example Live Demo#include using namespace std; template void fun(T a) { cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
54 Views
In this tutorial, we will be discussing a program to understand swapping of subranges of different containers in C++.For this we will be provided with vectors and lists, and we need to swap some of their elements.Example Live Demo#include #include #include #include using namespace std; int main(){ vector v = { -10, -15, -30, 20, 500 }; list lt = { 10, 50, 30, 100, 50 }; swap_ranges(v.begin(), v.begin() + 3, lt.begin()); for (int n : v) cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
465 Views
In this tutorial, we will be discussing a program to understand how to sum two integers without using arithmetic operators in C/C++.For adding two integers without using arithmetic operators, we can do this with either using pointers or using bitwise operators.ExampleUsing pointers#include using namespace std; int sum(int a, int b){ int *p = &a; return (int)&p[b]; } int main() { int add = sum(2,3); cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
503 Views
In this tutorial, we will be discussing a program to understand how to store a Data triplet in a vector in C++.To store three elements in a single cell of a vector we will creating a user defined structure and then make a vector from that user defined structure.Example Live Demo#include using namespace std; struct Test{ int x, y, z; }; int main(){ //creating a vector of user defined structure vector myvec; //inserting values myvec.push_back({2, 31, 102}); myvec.push_back({5, 23, 114}); myvec.push_back({9, 10, 158}); int s = myvec.size(); for (int i=0;i
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
391 Views
In this tutorial, we will be discussing a program to understand how to sort a vector in descending order using STL in C++.For sorting the given vector in descending order we will be using the sort() function from the STL library in C++.Example Live Demo#include using namespace std; int main(){ //collecting the vector vector a = { 1, 45, 54, 71, 76, 12 }; cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
422 Views
In this tutorial, we will be discussing a program to understand how to reverse a vector using STL in C++.For reversing a given vector we will be using the reverse() function from the STL library in C++.Example Live Demo#include using namespace std; int main(){ //collecting the vector vector a = { 1, 45, 54, 71, 76, 12 }; cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
163 Views
In this tutorial, we will be discussing a program to understand how to restrict dynamic allocation of objects in C++.For this we will be keeping the new operator function private so that objects cannot be created using it dynamically.Example Live Demo#include using namespace std; class Test{ //making new operator private void* operator new(size_t size); int x; public: Test() { x = 9; cout