This worksheet is intended to show the relationship between array names, subscripts, and pointer arithmetic. It may be helpful (but not required) to use a sheet of graph paper to represent where the variable values are stored (their addresses or storage locations). It is easier to understand the relationship if you can visualize how the information is stored.
SET-UP
void main() { int int_ary[10]={2,4,6,8}; // array of 10 integers char chr_ary[11]; // array of 11 characters, // room for 10 useable characters // and the null terminator . . . }
Assume that the space reserved for the
integer array starts at storage location 2000.
Assume that the space reserved for the character array starts at
storage location 1600.
PART 1
PART 2
Check the answers to PART 1 before
continuing. You need to understand #4-8 inorder to do PART 2.
Assume the following line of code has been executed.
strcpy(chr_ary, "computer");
The values in the integer array have not changed.
Determine the value of each expression below.
1. chr_ary chr_ary+0 *chr_ary *(chr_ary+0)
2. chr_ary+1 *chr_ary+1 *(chr_ary+1)
3. int_ary *int_ary *(int_ary+0)
4. int_ary+1 *int_ary+1 *(int_ary+1) int_ary[1]
5. *(chr_ary+3) chr_ary[3] chr_ary+3
6. chr_ary chr_ary[0] *chr_ary &chr_ary[0]
7. int_ary int_ary[0] *int_ary &int_ary[0]
8. &int_ary[0] &int_ary *int_ary+0 int_ary (CAREFUL!!!)
9. int_ary[2] *(int_ary+2) &int_ary[2] int_ary+2
10. int_ary+10 int_ary[10] *(int_ary+10)