??????????????????????????????????н?? C ????????????????????????????????????????????????????? C ???????????????????????????
????0x00 ????????
????????????????壺
????struct foo
????{
????/* some other variables...*/
????struct foo bar;
????};
????????????????? foo ?????????
????int main()
????{
????struct foo hello;
????return 0;
????}
?????????????????????????????????“??汬?”???
???????????????? Visual Studio 2015 ?????????δ???????????????????
????"bar"???δ????? struct"foo"
????????????????????????
????struct foo
????{
????/* some other variables...*/
????struct foo *bar;
????};
??????α????????????????????????????
????0x01 ?μ????? - ????????????????????壿
?????????????????????????屾?????????????????????????????????????????????????屾??????????? ??? ????????????
?????????????????? C ????????С????????£?????????????????????????????????????????????
??????????????????????????????
??????????????????????????屾???????????? δ???? ?????????????????屾??????? ??? ???????????????????????????? δ????? ????????????????????????????????壿
????0x02 ??????? - ??????????
????????????????????д????????δ???
#include <stdio.h>
int main()
{
int *foo;
char bar = 'a';
foo = &bar;
printf("%c "?? *foo);
return 0;
}
????????????????? a ?????? int ??????????????????? char ???????????????????????? foo ????? void * ?? long * ?? float * ??????????????????????????????????????????????????????????????????????????????????????壿
??????С??????????????????????? ????????????? ????????????????????????? ????? ??????????????????????????е????????
????0x03 ?μ???? - ?????????????
??????????????????????
#include <stdio.h>
int main()
{
int * foo;
char * bar;
char str[9] = { 'a'?? 'b'?? 'c'?? 'd'?? 'e'?? 'f'?? 'g'?? 'h'?? 'i' };
foo = &str;
bar = &str;
printf("%c %c %c "?? *foo?? *(foo + 1)?? *(foo + 2));
printf("%c %c %c "?? *bar?? *(bar + 1)?? *(bar + 2));
system("pause");
return 0;
}
?????????????£?
????a e i
????a b c
??????????? *(foo + 1) ?????? 4 ????sizeof(int) ?????????????????????????????????????????????????
??????????????????????
????struct foo
????{
????/* some other variables...*/
????struct foo *bar;
????};
????????????? struct foo* ????????????????????????? struct foo ???? δ????? ????????????????????????????????壿
????????????????????????????????? ?????????? ??????????????????????
????0x04 ??????
???????????????????????????????
#include <stdio.h>
int main()
{
void * p;
char str[9] = { 'a'?? 'b'?? 'c'?? 'd'?? 'e'?? 'f'?? 'g'?? 'h'?? 'i' };
p = &str;
printf("int *:  %c %c %c "?? *(int *)p?? *((int *)p + 1)?? *((int *)p + 2) );
printf("char *: %c %c %c "?? *(char *)p?? *((char *)p + 1)?? *((char *)p + 2) );
system("pause");
return 0;
}
???????н????
????int *:  a e i
????char *: a b c
????????????????飬???? void * ?????е???????????? void * p; ????и???? int * p; ?????????У?????????
????????????????????????е???????? ?????????? ?????????????????????
??????????????????????????????????????????????????????п???????в????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????