1.1 Ö¸ÕëµÄÈýÒªËØ
Êý¾ÝÀàÐÍ ±êʶ·û
1. ·²ÊÇÔÚ³ÌÐòÖпÉÒÔ·ÖÅäÄÚ´æ¿Õ¼ä(³ýÁËÄÚ´æ¹ÜÀíº¯Êý malloc callocÉêÇë¿Õ¼äÒÔÍâ)£¬Ò»¶¨ÊÇÔÚ¶¨Òå±äÁ¿£¬
¶¨Òå±äÁ¿Ò»¶¨ÊÇ·ûºÏ Êý¾ÝÀàÐͱäÁ¿Ãû ¸ñʽ
2. ÈçºÎÈ·¶¨±äÁ¿µÄÊý¾ÝÀàÐÍ£¿
1£©ÏÈÈ·¶¨±äÁ¿Ãû£¬±äÁ¿Ãû·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò
2£©È¥µô±äÁ¿Ãû£¬Ê£ÏµľÍÊDZäÁ¿µÄÊý¾ÝÀàÐÍ
Êý¾ÝÀàÐÍ [³¤¶È]--->Êý×éÀàÐÍ
Êý¾ÝÀàÐÍ *-------->Ö¸ÕëÀàÐÍ
Êý¾ÝÀàÐÍ (²ÎÊýÁбí)----->º¯ÊýÀàÐÍ
ÔÚÊý×éµÄÉùÃ÷ÖУ¬³ýÁË Êý×éÃû[³¤¶È] ʣϵľÍÊÇÊý×éÔªËصÄÀàÐÍ
ÔÚÖ¸ÕëµÄÉùÃ÷ÖУ¬³ýÁË *Ö¸ÕëÃû ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
ÔÚº¯ÊýµÄÉùÃ÷ÖУ¬³ýÁË º¯ÊýÃû(²ÎÊýÁбí) ʣϵľÍÊǺ¯Êý·µ»ØÖµÀàÐÍ
3. ÔÚ¸´ÔÓÊý¾ÝÀàÐ͵Ķ¨ÒåÖУ¬´øÓÐ * [] () ·ûºÅ, ½«Æäµ±×öÔËËã·û£¬¸ù¾ÝÔËËã·ûµÄÓÅÏȼ¶ºÍ½áºÏÐÔ£¬È·¶¨±êʶ·ûÓÅÏȸú˽áºÏ£¬ÄÇô¾ÍÊÇË£¿
±êʶ·û[³¤¶È]----->Êý×é £¬ ʣϵľÍÊÇÊý×éÔªËصÄÀàÐÍ
*±êʶ·û ------>Ö¸Õë ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
±êʶ·û(²ÎÊýÁбí)---->º¯Êý ʣϵľÍÊǺ¯Êý·µ»ØÖµÀàÐÍ
char *name[20];
//ÓÅÏȽáºÏ£¬---->name[20]---->Êý×é
//È¥µô name[20] ʣϵľÍÊÇÊý×éÔªËصÄÀàÐÍ char *--->Ö¸ÕëÀàÐÍ
//Ö¸ÕëÊý×é
char (*name)[20];
// ÓÅÏȽáºÏ£¬ *name ÓÅÏȽáºÏ£¬---->Ö¸Õë
//È¥µô *name ,ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ --->char [20]---->Êý×éÀàÐÍ
//Êý×éÖ¸Õë
char (*name)(int);
//ÓÅÏȽáºÏ£¬ *name ÓÅÏȽáºÏ£¬---->Ö¸Õë
//È¥µô *name ,ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ --->char (int)---->º¯ÊýÀàÐÍ
//º¯ÊýÖ¸Õë
char *name(int);
//ÓÅÏȽáºÏ---->name(int)----->º¯Êý
//È¥µô name(int) ʣϵľÍÊǺ¯ÊýµÄ·µ»ØÖµÀàÐÍ char *------>Ö¸Õë
//Ö¸Õ뺯Êý
char name[3][4];
//ÓÅÏȽáºÏ£ºname[3]----->Êý×é
//È¥µô name[3] ʣϵľÍÊÇÊý×éÔªËصÄÀàÐÍ char [4]--->Êý×éÀàÐÍ
//ÊÇÔªËØÀàÐÍΪÊý×éÀàÐ͵ÄÊý×飬---->¶þάÊý×é
int fun[5]; //fun
//¶¨Òå int [5] ÀàÐ͵ıäÁ¿ £¬ int [5] ---> Êý¾ÝÀàÐÍ [³¤¶È]--->Êý×éÀàÐÍ
//¶¨ÒåÊý×éÀàÐ͵ıäÁ¿ fun
char *p; //p
//±íʾ¶¨Òå char *ÀàÐ͵ıäÁ¿p char *------>Êý¾ÝÀàÐÍ *-------->Ö¸ÕëÀàÐÍ
int test(int , int);
//test
//int (int , int)---->Êý¾ÝÀàÐÍ (²ÎÊýÁбí)----->º¯ÊýÀàÐÍ
Ö¸ÕëÃû£ºÖ¸ÕëÃû--->±äÁ¿Ãû£¬·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò
Ö¸ÕëµÄÀàÐÍ£ºÈ¥µôÖ¸ÕëÃû£¬Ê£ÏµľÍÊÇÖ¸ÕëµÄÀàÐÍ£¬(È¥µô±äÁ¿Ãû£¬Ê£ÏµľÍÊDZäÁ¿µÄÊý¾ÝÀàÐÍ)
Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ£ºÔÚÖ¸ÕëµÄÉùÃ÷ÖУ¬³ýÁË *Ö¸ÕëÃû ÒÔÍâʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
Ö¸ÕëµÄ´óС¹Ì¶¨µÄ£¬ÓÉÖ¸Õë±¾ÉíµÄ´óС¾ö¶¨£¬¸úÖ¸ÕëËùÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍÎÞ¹Ø
Ö¸ÕëµÄÆ«ÒÆʵ¼ÊÉÏÓɶ¨ÒåÖ¸ÕëʱָÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ;ö¶¨£¬¶ø²»ÊÇÓÉʵ¼ÊÉÏÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐ;ö¶¨
int main() { int a = 100; //ÕûÐͱäÁ¿a int *p = &a; char *pf = &a; printf("%#p\n",p); printf("%#p\n",p+1); printf("%#p\n",pf); printf("%#p\n",pf+1); return 0; } |
p+1; //µØÖ·µÄÇ°ÒÆ
×¢Ò⣺
int *p; //Èç¹ûÖ¸Õ붨ÒåÔÚº¯ÊýÄÚÈÝ£¬
int main() { int *p; //Ö¸ÕëÀàÐ͵ľֲ¿±äÁ¿ //Èç¹ûûÓгõʼ»¯£¬ÔòϵͳĬÈϸ³ÖµÎªËæ»úÖµ //Ö¸ÕëÖ¸Ïò²»Ã÷È· //Èç¹ûÖ¸ÕëÒ»¿ªÊ¼Ö»¶¨Ò壬²»¸³Öµ£¬Ó¦µ±½«Ö¸ÕëÖÃ¿Õ //int *p = NULL; //²»ÈÃÖ¸ÕëÖ¸ÏòÈκÎÒ»¸öµØ·½
//Ò°Ö¸Õ룺 Ö¸ÕëµÄÖ¸Ïò²»Ã÷È·£¬¶øʹÓÃÖ¸Õë *p = 100; //Ò°Ö¸Õë¡£Ò°Ö¸Õë»áµ¼Ö³ÌÐòÔËÐбÀÀ£ return 0; } |