WWW W3schools Com CPP CPP - Function - Array Asp
WWW W3schools Com CPP CPP - Function - Array Asp
C#
BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY
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.