0% found this document useful (0 votes)
55 views

WWW W3schools Com CPP CPP - Function - Array Asp

The document discusses how to pass arrays as function parameters in C++. It provides an example of a function that takes an array as a parameter, loops through and prints the elements, and is called by passing an initialized array. It also notes that only the array name is needed when calling the function.

Uploaded by

Abenezer Asefa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

WWW W3schools Com CPP CPP - Function - Array Asp

The document discusses how to pass arrays as function parameters in C++. It provides an example of a function that takes an array as a parameter, loops through and prints the elements, and is called by passing an initialized array. It also notes that only the array name is needed when calling the function.

Uploaded by

Abenezer Asefa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

 Tutorials  Exercises  Services  

C#
 BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY

C++ Pass Array to a Function


❮ Previous Next ❯

Pass Arrays as Function Parameters


You can also pass arrays to a function:

Example
void myFunction(int myNumbers[5]) {
for (int i = 0; i < 5; i++) {
cout << myNumbers[i] << "\n";
}
}

int main() {
int myNumbers[5] = {10, 20, 30, 40, 50};
myFunction(myNumbers);
return 0;
}

Try it Yourself »

Example Explained
The function ( myFunction ) takes an array as its parameter ( int myNumbers[5] ), and
loops through the array elements with the for loop.

When the function is called inside main() , we pass along the myNumbers array, which
outputs the array elements.

Note that when you call the function, you only need to use the name of the array when
passing it as an argument myFunction(myNumbers) . However, the full declaration of
the array is needed in the function parameter ( int myNumbers[5] ).

❮ Previous Next ❯

COLOR PICKER



SPACES

UPGRADE

NEWSLETTER

GET CERTIFIED

REPORT ERROR

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate

    FORUM ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning. Tutorials, references, and examples are constantly reviewed to avoid
errors, but we cannot warrant full correctness of all content. While using W3Schools, you
agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999­2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by


W3.CSS.

You might also like