My Report

C++ STL Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which exception is thrown if the typecasting is not done properly?

2. What is the use of type() function in any container?

3. What will be the output of the following C++ code?

#include<iostream>
#include<any>
using namespace std;
int main()
{
	float val = 5.5;
	any var(val);
	cout<<var.type().name()<<endl;
	return 0;
}

4. What is the use of has_value() function in any container?

5. What will be the output of the following C++ code?

#include<iostream>
#include<any>
using namespace std;
int main()
{
	float val = 5.5;
	any var(val);
    cout<<any_cast<float>(var)<<endl;
	var.reset();
	if(!var.has_value())
        {
		cout<<"var is empty\n";
	}
	else{
		cout<<"var is not empty\n";	
	}
	return 0;
}

6. What is the use of reset() function?

7. What will be the output of the following C++ code?

#include<iostream>
#include<any>
using namespace std;
int main()
{
	float val = 5.5;
	any var(val);
	if(var.has_value())
        {
            cout<<"Var is not Empty\n";
        }
        else
        {
            cout<<"Var is Empty\n";
        }
	return 0;
}

8. What is the use of emplace() function?

9. In how many ways we can handle errors in any class?

10. What will be the output of the following C++ code?

#include<iostream>
#include<any>
using namespace std;
int main()
{
	float val = 5.5;
	any var(val);
	cout<<var<<endl;
	char c = 'a';
	var.emplace<char>(c);
	cout<<var<<endl;
	return 0;
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.