NEW
Font size
WorksheetsC++ Lambda Expression
Total questions: 20
Worksheet time: 11mins
What is lambda expression?
an anonymous function which could be written inline
group of statements that is given a name, and which can be called from some point of the program
a variable that stores the address of a function that can later be called through that variable
objects that can be treated as though they are a function or function pointer
int FooBar(int foo, double bar) { ... }
this is the declaration of...
function
function pointer
function object
lambda expression
int ( *awesome )(const char *, bool) = nullptr;
this is a declaration of...
function pointer
function
function object
lambda expression
This code snippet is an example of...
functor
function pointer
lambda expression
function
[](){}();
this is an example of ...
lambda expression
function
functor
function pointer
[]{};
What is wrong with that code.
Nothing is wrong
Compile Error
Runtime Error
Exception Thrown
[]{ cout << "Hello!"; };
What is the output shown in console...
(no output)
Hello!
"Hello"
Compile error!
[]{ cout << "Hello!"; }( );
What is the output shown in console...
(no output)
Hello!
"Hello"
Compile error!
what is hi?
void (*hi)()
int hi
void hi
void *hi
void hi()
What is the output?
Hello, scope!
Hello, lambda! 2
Hello, world!
Hello, scope!
Hello, lambda 1!
Hello, lambda! 2
Hello, scope!
Hello, lambda 1!
Hello, lambda! 2
[ ]
what does that lambda capture mean?
it's not capturing any variable from outside
it's capturing all variables from outside
it's capturing all variables from outside but Read Only
it's capturing all variables from outside both Read and Write
[=, &x]
What does that lambda capture mean?
Accepting all outside vars Read Only, but x is Read and Write
Accepting all outside vars Read Write, but x is Read Only
Accepting only x which is Read Only.
Accepting only x which is Read/Write
What is the output of line 13?
50 20 30
10 24 77
10 20 30
50 24 77
What is the problem with that code?
i is read only, could not assign any value to i
nothing is wrong
invalid capture
it's not proper lambda function
the function never been called
what is the output?
26
13
42
60
Which is the INCORRECT statement of lambda?
Improve reusability
Anonymous
Compact
Improve locality
Which is the CORRECT capture?
[&x = i, y = j + 4, k = 77]
[&, x, &y]
[=, &x, y]
[x, &x]
hi is ...
function pointer
function
functor
lambda expression
hello is ...
function
functor
function pointer
lambda expression
What is the output?
Hello, oppa!
Farewell, oppa!
Hello, oppa!
Farewell, oppa!
Error!
