How to Pass an Array into a Lambda Function in C++? Last Updated : 06 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a lambda function, also known as a lambda expression, is a way of defining an anonymous function object right at the location where it is invoked or passed as an argument to a function. In this article, we will learn how to pass an array into a lambda function in C++. Passing an Array into a Lambda Function in C++To pass an array into a lambda function in C++, we can simply pass the array as an argument to the lambda function. Inside the lambda function, we can access the elements of the array just like we would in a regular function in C++. Note: Remember to pass the size of the array as a parameter too. C++ Program for Passing an Array into a Lambda Function C++ // C++ Program to illustrate how to pass an array into a // lambda function #include <iostream> using namespace std; // Define a lambda function that takes an array as a // parameter auto printArray = [](int arr[], int size) { for (int i = 0; i < size; ++i) { cout << arr[i] << " "; } cout << endl; }; int main() { // Creating an array int arr[5] = { 1, 2, 3, 4, 5 }; // Passing the array into the lambda function printArray(arr, 5); return 0; } Output1 2 3 4 5 Time complexity: O(N), where N is the number of elements in the array.Auxiliary Space: O(1) If the lambda expression is in the same scope as that of the array, we can also use the capture clause of the lambda expression to accesss the array inside it. Comment More infoAdvertise with us Next Article How to Pass an Array into a Lambda Function in C++? D denzirop9v Follow Improve Article Tags : C++ Programs C++ CPP-Functions C-Arrays CPP Examples +1 More Practice Tags : CPP Similar Reads How to Pass a 3D Array to a Function in C++? In C++, a 3D array is a multidimensional array that has three dimensions, i.e. it can grow in three directions. In this article, we will learn how to pass a 3D array to a function in C++. Pass a 3D Array to a Function in C++ Just like normal 1-dimensional arrays, we can't pass the array to a functio 2 min read How to Pass an Array Pointer as a Function Argument in C++? In C++, a common situation arises where we have to pass an array to a function to perform some processing. This can be done by passing an array pointer as a function argument. In this article, we will learn how to pass an array pointer as a function argument in C++. Passing Array Pointer to Function 2 min read How to Convert an Array to a Vector in C++? In this article, we will learn how to convert the given array into vector in C++.The simplest method to convert an array to vector is by using range constructor of vector. Letâs take a look at an example:C++#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {1, 3, 6, 2, 9}; 3 min read How to Copy a Vector to an Array in C++? In C++, vectors are dynamic arrays that can grow and reduce in size as per requirements. Sometimes, we may need to copy the contents of a vector to the POD array. In this article, we will learn how to copy a vector to an array in C++. Example: Input: myVec = {10,20,30,40,50,60};Output: array: {10,20 2 min read How to Create a Pointer to a Function in C++? In C++, a function pointer is a variable that stores the address of a function that can later be called through that function pointer. It is useful for passing functions as parameters to other functions(callback functions) or storing them in data structures. In this article, we will learn how to use 2 min read Like