Professional Documents
Culture Documents
#include <iostream>
//Illustrates how arrays are passed as parameters and that an array name is
//a pointer that contains the address of the first element in the array
int main() {
int list[5];
list[j] = j;
for (int j = 0; j < 5; j++) //Prints 5 integers stored (0, 1, 2, 3 ,4 )
cout << "Initial list[" << j <<"] is " << list[j] << endl;
/*
Initial list[0] is 0
Initial list[1] is 1
Initial list[2] is 2
Initial list[3] is 3
Initial list[4] is 4
************************
*/
test1(list, 5); //list matches up with int val[] in the test1 parameter list
// val and list share the same memory location but val is temporary
cout << "list[" << j <<"] is " << list[j] << endl;
/*
list[0] is 0
list[1] is 2
list[2] is 4
list[3] is 6
list[4] is 8
************************
*/
test2(&list[0], 5);
cout << "list[" << j <<"] is " << list[j] << endl;
/*
list[0] is 0
list[1] is 6
list[2] is 12
list[3] is 18
list[4] is 24
************************
*/
//ptr of test3
cout << "list[" << j <<"] is " << list[j] << endl;
list[0] is 0
list[1] is 60
list[2] is 120
list[3] is 180
list[4] is 240
*/
system ("pause");
return 0;
val[j] *= 2;
val[j] *= 3;
(*ptr) *= 10;
ptr++;
}
/*
Initial list[0] is 0
Initial list[1] is 1
Initial list[2] is 2
Initial list[3] is 3
Initial list[4] is 4
************************
list[0] is 0
list[1] is 2
list[2] is 4
list[3] is 6
list[4] is 8
########################
list[0] is 0
list[1] is 6
list[2] is 12
list[3] is 18
list[4] is 24
list[0] is 0
list[1] is 60
list[2] is 120
list[3] is 180
list[4] is 240
*/