C array names are not assignable variables


In the programming language C, array names are not assignable variables. Therefore, we can't copy an array directly with an assignment statement. As a contrast, objects of struct types can be copied.
The following code snippet illustrates the difference:
struct {int i; float f;} x, y;
int a[10], b[10];
y = x; /* Copy x to y, OK */
b = a; /* Illegal assignment */
Now if we wrap an array inside a struct:
typedef int array[5];
typedef struct {array v;} wrapped;
then we can copy a wrapped array with assignment
wrapped wa, wb;
wb = wa; /* Copy wrapped array a to wrapped array b */
Use this idea to implement an array-copying routine:
/* copy (unwrapped) array a to array b */
void array_copy(array a, array b)
{
}
such that when the following driver routine executes,
int main()
{
array a = {1,2,3,4,5}, b = {6,7,8,9,10};
printf("Before: b=[%d,%d,%d,%d,%d]n",
b[0],b[1],b[2],b[3],b[4]);
array_copy(a,b);
printf("After: b=[%d,%d,%d,%d,%d]n",
b[0],b[1],b[2],b[3],b[4]);
}
we get the output:
Before: b=[6,7,8,9,10]
After: b=[1,2,3,4,5]
Note that you should not use any element-by-element copy strategy to implement the copying routine. 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: C array names are not assignable variables
Reference No:- TGS097126

Expected delivery within 24 Hours