My Report

Advanced C++ Test – 1


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. What will be the output of the following C++ code?

#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [&]() 
        {
		a = 10;
	};
	check();
	cout<<"Value of a: "<<a<<endl;
	return 0;
}

2. What is the syntax of defining lambda expression?

3. What is lambda expression in C++?

4. Which is the correct syntax of capturing a variable 'X' by reference and other variable 'Y' by value in lambda expression?

5. What is the correct statement about lambda expression?

6. Which of the following operator is used to capture all the external variable by value?

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

#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [](int x) 
        {
		if(x == 0)
			return false;
		else
			return true;
	};
	cout<<check(a)<<endl;
	return 0;
}

8. Which of the following operator is used to capture all the external variable by reference?

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

#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	int b = 5;
	auto check = [&a]() 
        {
		a = 10;
		b = 10;
	}
	check();
	cout<<"Value of a: "<<a<<endl;
	cout<<"Value of b: "<<b<<endl;
	return 0;
}

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

#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [=]() 
        {
		a = 10;
	};
	check();
	cout<<"Value of a: "<<a<<endl;
	return 0;
}

11. In how many ways we can capture the external variables in the lambda expression?

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

#include<iostream>
using namespace std;
int main()
{
	int x = 5;
	auto check = []() -> bool 
        {
		if(x == 0)
			return false;
		else
			return true;
	};
	cout<<check()<<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.