/* Unmodifiable Array * const_none.cpp * Purpose: to show what happens to array value in main if not "protected" * when array (pointer) is passed to a function, and function * may change array's value back in main() by mistake... * * May 17 2005 */ #include using namespace std; #define MAX 10 void display( int a[], int n); int main( ) { int i, a[MAX]; for (i = 0; i < MAX; i++) a[i] = i * i; display (a, MAX); cout << "contents are array \"a\" are: " << endl; for (i = 0; i < MAX; i++) cout << a[i] << " "; cout << endl; return 0; } /* display the contents of a[n] */ void display( int a[], int n) { int i; for (i = 0; i < n; i++) cout << "a[" << i + 1 << "] is: " << a[i] << endl; }