Skip to content

Commit 58dfeb1

Browse files
authored
Merge pull request #4 from adityyyy/adityyyy-patch-3
Create pairCreation.cpp
2 parents ad61f56 + 9d391dd commit 58dfeb1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

CPP/set & pair/pairCreation.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
int main(){
4+
5+
//Pair is a way of creating a Composite datatypes
6+
// pair<int,int> p; //a pair of 2 ints
7+
// pair<int,string> p; //a pair of an int and a string
8+
// pair<vector<int>,string> p; //a pair of a (vector of int) and a string
9+
10+
//accessing the elements using .first and .second
11+
pair<string,int> p={"hello", 6};
12+
cout<<p.first<<" "<<p.second; //prints: hello 6
13+
14+
//Advantages: in case, you want to return multiple values from a function.
15+
16+
//pair<vector<pair<int,vector<int>>>, string>
17+
18+
pair<int,string> a={4, "xyz"};
19+
p.first = 13;
20+
cout<<p.first<<" "<<p.second;
21+
22+
}

0 commit comments

Comments
 (0)