#include <stdio.h>
int main()
{
printf("------------------------\n");
int n = 1000;
char * p = (char*) &n;
printf("%x \n", p);
p = (char*) n;
printf("%d \n", p);
printf("------------------------\n");
int i;
int k;
int pos = 0;
int x;
int y;
int size = sizeof(int);
int * xy = (int *) malloc (2* 3* size);
memset(xy, 0x00, 2*3*size);
for(y=0; y<3; y++)
{
for(x=0; x<2; x++)
{
*(xy+pos) = pos+1000;
printf("xy+pos : %x pos : %d *(xy+pos) : %d \t\t", xy+pos, pos, *(xy+pos));
pos = pos + size;
}
printf("\n");
}
printf("------------------------\n");
//안됨.
// char * z = (char*) malloc (5);
// z+1 = xy;
printf("------------------------\n");
int max = pos;
char* z[5];
for(i=0; i<5; i++)
{
z[i] = xy;
int * p = (int*) z[i];
// p = (int*) xy;
pos = 0;
for(y=0; y<3; y++)
{
for(x=0; x<2; x++)
{
printf("%x : %d \t", p+pos, *(p+pos));
pos = pos + size;
}
printf("\t\t");
}
printf("\n");
}
printf("------------------------\n");
int a_xy[2][3];
for(i=0; i<5; i++)
{
int * p = (int*) z[i];
pos = 0;
for(y=0; y<3; y++)
{
for(x=0; x<2; x++)
{
printf("%x : %d \t", p+pos, *(p+pos));
pos = pos + size;
}
printf("\t\t");
}
printf("\n");
}
printf("------------------------\n");
for(i=0; i<5; i++)
{
int * p = (int*) z[i];
pos = 0;
for(y=0; y<3; y++)
{
for(x=0; x<2; x++)
{
a_xy[x][y] = *(p+pos);
printf("%d \t", a_xy[x][y]);
pos = pos + size;
}
printf("\t\t");
}
printf("\n");
}
printf("------------------------\n");
int tpos = 0;
for(i=0; i<5; i++)
{
int * p = (int*) z[i];
printf("%x \n", z[i]);
memcpy(&a_xy[0][0], p+tpos, 2*3);
// tpos = tpos + 2*3*size; 안됨.
tpos = tpos + 2*3;
for(y=0; y<3; y++)
{
for(x=0; x<2; x++)
{
printf("%d \t", a_xy[x][y]);
}
}
printf("\n");
}
free(xy);
return 0;
}