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:
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 <iostream> using namespace std; void printArr(int arr[], int size) { for(int x = 0; x < size; x++) { cout << arr[x] << " "; } } int main() { int arr[] = {1, 2, 3, 4}; printArr(arr, 4); }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 2.94
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:
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 <iostream> using namespace std; void printArr(int arr[], int size) { for(int x = 0; x < size; x++) { cout << arr[x] << " "; } } int main() { int arr[] = {1, 2, 3, 4}; printArr(arr, 4); }
Дякуємо за ваш відгук!