Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // More tutorials at BrandonHok.com
- #include <iostream>
- // C++ Crackdown 3.5 Passing and Using An Array
- // An array is a long list of items
- // It is literally.... [stuff, stuff, stuff, stuff, pancakes, chocolates]
- // Let's check out how to declare one and then pass one into a function
- // This is the function prototype for an array
- // Notice some slight differences here
- void arrayPowerGoodness(int arrayname[], int sizeofthearray);
- int main()
- {
- // Set up the array
- // A constant is needed here because when passing, we cannot have the array be manipulatable
- // This part is a bit confusing, you may need to break it down and fully understand what's going on
- const int arraySize = 5;
- int arrayName[arraySize] = { 1,2,3,5,6 } ;
- // Call the array propertly after making the function below
- arrayPowerGoodness(arrayOne, arraySize);
- system("pause");
- }
- // This function allows to print every element of the array
- // Try it out
- void arrayPowerGoodness(int a[], int size)
- {
- for (int i = 0; i < size; ++i)
- std::cout << a[i];
- }
- // Can you make your own array function but use a while method instead?
- // Can you select specific numbers of the array and add them up?
- // Can you modify a specific element of the array?
- // What do you think arrays are useful for?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement