Don't like ads? PRO users don't see any ads ;-)
Guest

arrays and pointers

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void printArray(int *theArray, int size) {
  5.       cout << "Pointer notation print: ";
  6.       for(int i=0; i<size; i++) {
  7.             cout << *(theArray + i) << " ";
  8.       }
  9.       cout << endl << "Array notation print: ";
  10.       for(int i=0; i<size;i++) {
  11.             cout << theArray[i] << " ";
  12.       }
  13.       cout << endl << endl;
  14. }
  15.  
  16.  void reverseArray(int *theArray, int size) {
  17.       int newArray[10];
  18.       for(int i=0; i<size; i++) {
  19.             newArray[i] = theArray[size-1-i];
  20.       }
  21.       cout << "Reversed array: ";
  22.       for(int i=0; i<size; i++) {
  23.             cout << newArray[i] << " ";
  24.       }
  25. }
  26.  
  27. int main() {
  28.       int arrayOfValues[10] = {1,2,3,4,5,6,7,8,9,10};
  29.       int arraySize=10;
  30.       printArray(arrayOfValues,arraySize);
  31.       reverseArray(arrayOfValues,arraySize);
  32.       return 0;
  33. }