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;
}
#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;
}A. Value of a: 5
B. Value of a: 10
C. Error
D. Segmentation fault
Answer: Option C

Join The Discussion