Ö¸ÕëµÄÆ«ÒÆÓëÖ¸ÕëµÄ´óС
1. Ö¸ÕëËùÕ¼µÄ¿Õ¼äµÄ´óС£ºÓÉÖ¸Õë±¾Éí¾ö¶¨£¬¸úÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍÎ޹أ¬Ò»°ãÊÇ4¸ö×Ö½Ú£¬Ò²ÓпÉÄÜÊÇ8¸ö×Ö½Ú£¨64λµÄ±àÒëÆ÷£©£¬win32ƽ̨Ï£¬Ö¸ÕëµÄ¿Õ¼ä´óС4¸ö×Ö½Ú
#include <stdio.h>
int main() {
int b = 109; int* p = &b; char *pf; double *pt; short *pm;
printf("%d\n",sizeof(p)); //int *, p±äÁ¿¶ÔÓ¦µÄÀàÐÍËùÕ¼¿Õ¼ä´óС printf("%d\n",sizeof(pf)); //char * printf("%d\n",sizeof(pt)); //double * printf("%d\n",sizeof(pm)); //short *
printf("%d\n",sizeof(int *)); printf("%d\n",sizeof(char *)); printf("%d\n",sizeof(double *)); printf("%d\n",sizeof(short *));
//È·¶¨±äÁ¿µÄÀàÐÍ£¿ //ÔÚ±äÁ¿µÄ¶¨ÒåÖУ¬³ýÁ˱äÁ¿Ãû£¬Ê£ÏµľÍÊDZäÁ¿µÄÀàÐÍ //1£©±äÁ¿Ãû£º·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò // int shgd_san; //shgd_san±äÁ¿Ãû£¬ÀàÐÍ int //char *pg; //pg ±äÁ¿£¬ÀàÐÍ£º char *ÀàÐÍ£¬--->Êý¾ÝÀàÐÍ *--->Ö¸ÕëÀàÐÍ //float kjh[10]; //kjh±äÁ¿£¬ÀàÐÍ£¬ float [10] ---->Êý¾ÝÀàÐÍ [³¤¶È]--->Êý×éÀàÐÍ } |
2. Ö¸ÕëµÄÆ«ÒÆÊÇÓɶ¨ÒåÖ¸ÕëʱָÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ;ö¶¨£¬¶ø²»ÊÇʵ¼ÊÉÏÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ;ö¶¨£¬Ò»°ãÇé¿öÏ£¬¶¨ÒåÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ͸úʵ¼ÊÉÏÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐͱ£³ÖÒ»ÖÂ
int main() { int b = 109; // b Êǿռ䣬bµÄÀàÐÍ int //&b £º ±íʾb¿Õ¼äµÄÊ×µØÖ·£¬&b --->Ö¸Õë--->Êý¾ÝÀàÐÍ * //&b : int *
int* p = &b; //¶¨ÒåÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ int //ʵ¼ÊÉÏÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ int
char *pf =(char *)&b; //¶¨ÒåÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char //ʵ¼ÊÉÏÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ int
//Ö¸Õë+ÕûÊý£º ±íʾָÕëµÄÆ«ÒÆ£¬Æ«ÒƵÄ×Ö½ÚÊý //Æ«ÒƵÄ×Ö½ÚÊý£¬Óɶ¨ÒåÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ;ö¶¨ printf("%#p\n",p); printf("%#p\n",pf); printf("%#p\n",&b);
printf("%#p\n",p+1); printf("%#p\n",pf+1); printf("%#p\n",&b+1);
unsigned int a = 0XAABBCCDD; //½»»»¸ß°ËλµÍ°Ëλ unsigned char *pt = &a; unsigned char tmp;
tmp = *pt; *pt = *(pt+3); *(pt+3) = tmp; printf("%#X\n",a); } |
int main() { int b = 123456789; char *pm = (char *)&b; int *ph = &b; short *pk = &b;
//pm = pm+1; // //*pm = *pm+1;
pk = pk +1; //Æ«ÒÆ2¸ö×Ö½Ú *pk = *pk + 2;
//char [-128,127] //printf("%d\n",*pm); // ¶ÁÈ¡pmËùÖ¸ÏòµÄ¿Õ¼äµÄÄÚÈÝ 206-256=-50 printf("%d\n",*pk); printf("%d\n",*ph); // ¶ÁÈ¡phËùÖ¸ÏòµÄ¿Õ¼äµÄÄÚÈÝ 123457045 printf("%d\n",b); //b µÄÖµ 123457045 } |