pranay_teja
10/20/2018 - 10:37 AM

Pairs_Syntax

#include<bits/stdc++.h>
using namespace std;

// #CPP_STL #Pairs

int main(){
    // Pairs are C++ defined class
    // pair< data_type1, data_type 2> p
    // p.first gives first element in pair
    // p.second gives second element in pair
	pair<int,int> complex_num;
	complex_num.first=2;	// real part
	complex_num.second=3;	// imaginary part
	cout<<complex_num.first<<" + i"<<complex_num.second<<endl;

	// pair of different data types
	pair<int,bool> num_present;
	num_present.first=30;
	num_present.second=true;
	cout<<num_present.first<<" is ";
	if(num_present.second==true){
		cout<<"present";
	}
	cout<<endl;
	
	// defining a pair
	pair<int,int> co_ord = {2,3};
	cout<<"X co-ord is "<< cod_ord.first<<endl;
	cout<<"Y co-ord is "<< cod_ord.second<<endl;
	
	return 0;
}