How do structures in C interact with pointers or arrays?
#include <stdio.h>
struct FIRST {
int A[3];
};
union ALL {
struct FIRST TWO[2];
int ONE[6];
};
int main (int argc, const char * argv[]) {
int i,j,count;
union ALL a;
count=1;
for (i=0; i<2; i++) {
for (j=0; j<3; j++) {
a.TWO[i].A[j]=count;
count++;
}
}
for (i=0; i<6; i++)
{
printf("ONE[%i] = %i\n",i,a.ONE[i]);
}
return 0;
} |
Output:
ONE[0] = 1 ONE[1] = 2 ONE[2] = 3 ONE[3] = 4 ONE[4] = 5 ONE[5] = 6
|
|