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

bookPass 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:

void printArr(int arr[], int size) {
    for(int x = 0; x < size; x++) {
        cout << arr[x] << " ";
    }
}

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)

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 9

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 2.94

bookPass the Array

Veeg om het menu te tonen

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:

void printArr(int arr[], int size) {
    for(int x = 0; x < size; x++) {
        cout << arr[x] << " ";
    }
}

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)

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 9
some-alt