1 분 소요

#include
#ifdef ____what____
음.. 그러니까.. 구조체로 선언한 내용을 다시 배열로 잡아서
거기서 배열을 출력하는건 어떨까??? 공용체도 사용해보고.. 이거 재미있겠지?
함 해보자~~~ 음 언제하지.. 모.. 내일해도 되구 아자 해보자구~~
지금은 레포트중 하하
#endif

typedef struct _test
{
int test_int;
char test_char;
double test_double;
}test_typedef, *test_typedef_point;

int main(int argc, char *argv[])
{
test_typedef test[10]; //struct 형태로 배열을 만듬
test_typedef * test_p[10]; //struct 형태로 배열 포인터를 만듬
test_typedef_point test_point[10]; //struct pointer형태로 배열을 만듬

test[0].test_int=1;
test[0].test_char=’a’;
test[0].test_double=99;

test[1].test_int=1;
test[1].test_char=’a’;
test[1].test_double=99;

test_p[0]->test_int=1;
test_p[0]->test_char=’a’;
test_p[0]->test_double=99;


test_point[0]->test_int=2;
test_point[0]->test_char=’b’;
test_point[0]->test_double=999;

//#define PRINT_DATA

#ifdef PRINT_DATA
printf(“%d %c %f
“,test[0].test_int,test[0].test_char,test[0].test_double );
printf(“%d %c %f
“,test_p[0]->test_int,test_p[0]->test_char,test_p[0]->test_double );
printf(“%d %c %f
“,test_point[0]->test_int,test_point[0]->test_char,
test_point[0]->test_double );
#endif

#define ADDRESS_TEST

#ifdef ADDRESS_TEST
printf(“
=== test_typedef test[10] ===
“);

printf(“ int %d ~ %d
char %d ~ %d
double %d ~ %d

, &test[0].test_int,&test[0].test_char ,
&test[0].test_char,&test[0].test_double
, &test[0].test_double, &test[1].test_int);

printf(“test[2] %d
“,sizeof(test[2]));
//내가원하는 주소에서 +1씩 추가하여 보여주기 위함
printf(“test ====»»»» %d
“,(char)*(&test[0].test_char+0));
//여기서 문제점은 Char이 저장되는 공간이 4바이트인것에 반해서
// 크기는 1 바이트라는 것이다 .. 왜 그럴까??

printf(“int %d char %d double %d

, sizeof(test[0].test_int), sizeof(test[0].test_char), sizeof(test[0].test_double) );

printf(“
=== test_typedef * test_p[10] ===
“);

printf(“int %d char %d double %d

, &test_p[0]->test_int, &test_p[0]->test_char, &test_p[0]->test_double );

printf(“int %d char %d double %d

, &test_p[1]->test_int, &test_p[1]->test_char, &test_p[1]->test_double );

printf(“int %d char %d double %d

, &test_p[2]->test_int, &test_p[2]->test_char, &test_p[2]->test_double );

printf(“
=== test_typedef_point test_point[10] ===
“);
//결국 포인터로 잡게 되면 각 배열은 순차적으로 입력되는것이 아니라
//이곳 저곳으로 입력된다.

printf(“int %d char %d double %d

, &test_point[0]->test_int, &test_point[0]->test_char,
&test_point[0]->test_double );

printf(“int %d char %d double %d

, &test_point[1]->test_int, &test_point[1]->test_char,
&test_point[1]->test_double );

printf(“int %d char %d double %d

, &test_point[2]->test_int, &test_point[2]->test_char,
&test_point[2]->test_double );\

//주소값을 찾아서 그 주소값부터 내가 원하는 양(type)만큼 보고싶을때
//아래와 같은 방법으로 사용하면 된다.
//이런것을 케스팅이라고 한다.
printf(“test ====»»»» %f
“,(double )*(&test_point[0]->test_double ));

#endif
return 0;
}\

태그:

카테고리:

업데이트: