How to Read an Array from the Keyboard
Consider the following code snippet:
int i; //n = 10 = size of array
int a[10];
printf(“ Enter total number of elements in array:”);
for (i =0; i scanf(“%d”, &a[i]);
The Issue of Copying Arrays
An array is an object. There is a difference between an array and the variable that references it. Thus,
that array and the reference variable are two separate entities. This difference becomes essential
when you wish to copy the contents of one array to another. The following is the
wrong way
of
copying an array:
int a1[ ] = {1, 3, 5, 7};
int a2[ ] = a1; //error, no copying will be done.
These two statements will not copy the contents of a1 to a2. Instead a copy of the address
stored in a1 is stored in a2. Thus, after this statement executes, both the a1 and a2 variables
Do'stlaringiz bilan baham: |