Saturday, April 28, 2012

8.5

In C,
int x[10];
int y[10];


Why will the statement x = y not compile?


x = y will not compile because the name of an array passes the address of the first element of an array, not the values stored in the array.  In order to copy the array, the assignment statement should be as follows


for(int i=0, i<10, i++)
    {
           x[i] = y[i];
    }

No comments:

Post a Comment