/*! * file ArrayReference.cpp * author Hasan * date 20 June 2014 14:41:04 * This exercise shows that even the array get sorted * but Memory location is the same */ #include <iostream> #include <iomanip> #include <ctime> using namespace std; void printArray2(int[]); const int SIZE = 5; int main(){ int array[SIZE] = { 3,1,4,6,5}; cout << "Array & Memory Reference\n"; printArray2(array); printArray2(array); cin.get(); return 0; } void printArray2(int a[SIZE]){ for (int i = 0; i < SIZE; i++){ cout << setw(10) << a[i]; } cout << endl; for (int i = 0; i < SIZE; i++){ cout << setw(10) << &a[i]; for (int j = 1; j < SIZE-i; j++){ if (a[i]>a[i+1]){ int temp = a[i]; a[i] = a[i+1]; a[i+1] = temp; } } } cout << endl; }
output:
Array & Memory Reference 3 1 4 6 5 00F7FE90 00F7FE94 00F7FE98 00F7FE9C 00F7FEA0 1 3 4 5 6 00F7FE90 00F7FE94 00F7FE98 00F7FE9C 00F7FEA0
Post a Comment