Q1)Read the following code :
struct comp
{
bool operator() (unsigned int x, unsigned int y) {
return (x % 10) < (y % 10);
}
}
set < unsigned int, comp > mySet = {9, 12};
for ( int x : mySet) cout << x << ' ';
What is the output? What is the maximum possible size of mySet?
- depends upon the memory available, output is 12 9
- 10^8 , output is 12 9
- 10^1 , output is 12 9
- 10^2 , output is 9 12
Doubt: Why the maximum size is 10^1 but When i use max_size() it shows a int greater than 10 digits
Q2)Study the following code carefully.
struct student{
string name;
float cgpa;
student(string name, float cgpa){
this -> name = name;
this -> cgpa = cgpa;
}
};
struct comp{
bool operator () (const student& x, student y) {
return x.name < y.name;
}
};
set < student, comp > batch;
The above code compiles successfully. Choose which of the following declarations of the function operator () will give a compilation error.
1)bool operator () (student x, student y)
2)bool operator () (const student& x, const student& y)
3)bool operator () (student& x, const student& y)
4)None of these
Doubt: Why option 3 is correct?