Skip to main content

Lambda Functions

1).What is a lambda function in C++?

1) A function defined inline
2) A function that returns a lambda expression
3) A function with a fixed signature
4) None of the above

2).Which of the following is the correct syntax for a simple lambda function?

1) [] { // code }
2) [int a] { // code }
3) [a] { // code }
4) None of the above

3).What does the '[]' in a lambda function denote?

1) Capture clause
2) Return type
3) Argument list
4) None of the above

4).What is the purpose of the 'auto' keyword in lambda functions?

1) To automatically deduce the return type
2) To automatically deduce the arguments
3) To capture all variables by reference
4) None of the above

5).How do you capture a variable by reference in a lambda?

1) [&a] { // code }
2) [a] { // code }
3) [] { // code }
4) None of the above

6).Can lambda functions accept parameters?

1) Yes
2) No
3) Only for return types
4) None of the above

7).What is the return type of a lambda function if not specified?

1) auto
2) void
3) int
4) Depends on the body of the function

8).Can lambda functions be assigned to variables?

1) Yes
2) No
3) Only for const variables
4) Only for functions

9).How do you call a lambda function?

1) By using the variable it is assigned to
2) By using the function name
3) By using the capture clause
4) None of the above

10).Can lambda functions be used with STL algorithms?

1) Yes
2) No
3) Only with specific algorithms
4) None of the above