Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Pass the Array | Functions
C++ Intermediate | Mobile-Friendly
course content

Conteúdo do Curso

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Pass the Array

You can pass to your function whatever parameters you want, and even arrays!

For instance, here, we pass the array and its size as arguments:

python

Here we pass to the function an integer array and its size as arguments . Then we go through the array using for loop to print each element. The whole code:

12345678910111213
#include &ltiostream&gt using namespace std; void printArr(int arr[], int size) { &nbsp;&nbsp;&nbsp;&nbsp;for(int x = 0; x < size; x++) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout << arr[x] << " "; &nbsp;&nbsp;&nbsp;&nbsp;} } int main() { &nbsp;&nbsp;&nbsp;&nbsp;int arr[] = {1, 2, 3, 4}; &nbsp;&nbsp;&nbsp;&nbsp;printArr(arr, 4); }
copy
question-icon

Pass the string array x as an argument of the function:

void myFunc(,size)

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 9
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt