Why can't I assign arrays as &a = &b?
I have a problem assigning an array like:
int a[];
int b[] = {1,2,3};
&a = &b;
I know I could use pointers but I want to try it that way...
You can't assign arrays in C. You can copy them with the memcpy()
function, declared in <string.h>
:
int a[3];
int b[] = {1,2,3};
memcpy(&a, &b, sizeof a);
That way doesn't work, as you have found. You cannot assign arrays in C.
Structs, however, are assignable. So you can do this:
typedef struct
{
int x[3];
} T;
T a;
T b = { { 1, 2, 3 } };
a = b;