
arrays and pointers
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.87 KB | hits: 19 | expires: Never
#include <iostream>
using namespace std;
void printArray(int *theArray, int size) {
cout << "Pointer notation print: ";
for(int i=0; i<size; i++) {
cout << *(theArray + i) << " ";
}
cout << endl << "Array notation print: ";
for(int i=0; i<size;i++) {
cout << theArray[i] << " ";
}
cout << endl << endl;
}
void reverseArray(int *theArray, int size) {
int newArray[10];
for(int i=0; i<size; i++) {
newArray[i] = theArray[size-1-i];
}
cout << "Reversed array: ";
for(int i=0; i<size; i++) {
cout << newArray[i] << " ";
}
}
int main() {
int arrayOfValues[10] = {1,2,3,4,5,6,7,8,9,10};
int arraySize=10;
printArray(arrayOfValues,arraySize);
reverseArray(arrayOfValues,arraySize);
return 0;
}