typedef ¹Ø¼ü×Ö
1. ×÷ÓãºÀàÐÍÖض¨Òå¹Ø¼ü×Ö£¬±íʾ¶ÔÒÑÓеÄÊý¾ÝÀàÐÍÈ¡±ðÃû
2. ¸ñʽ£ºtypedefÔÀ´µÄÀàÐÍÃûеÄÀàÐÍÃû
3. ˵Ã÷£º typedef ²»ÊÇ´´½¨ÐµÄÀàÐÍ£¬ÒѾ´æÔÚµÄÀàÐÍÈ¡±ðÃû
еÄÀàÐÍÃû·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò
//еÄÀàÐÍÃû·ûºÏ±êʶ·ûµÄÃüÃû¹æÔò //typedef ÔÀ´µÄÀàÐÍÃû еÄÀàÐÍÃû typedef int INT; //¶ÔintÀàÐÍÖض¨ÒåÈ¡ÃûINT typedef unsigned char u8;//¶Ôunsigned charÀàÐÍÖض¨ÒåÈ¡Ãûu8 typedef int *PNT; //¶Ô int *ÀàÐÍÖض¨ÒåPNT typedef int ARRY[3]; //¶Ô int [3]ÀàÐÍÖض¨ÒåARRY int main() { int a = 100; //µÈ¼ÛÓÚ INT a INT b = 123; //µÈ¼ÛÓÚ int b
u8 d = 257; //µÈ¼ÛÓÚ unsigned char d;
PNT f = &a; //µÈ¼ÛÓÚ int *f //==================================================== ARRY h ={80,32,45} ; //µÈ¼ÛÓÚ int h[3]; //h ÊÇÊý×飬Êdz¤¶ÈΪ3ÔªËØÀàÐÍΪintÀàÐ͵ÄÊý×é for(int i = 0; i < sizeof(h)/sizeof(h[0]); i++) { printf("%d ",h[i]); } printf("\n"); //====================================================== ARRY buf[4]; //buf : 4 ¸öһάÊý×é int [3]¹¹³É //¶¨Òå ARRY [4]ÀàÐ͵ıäÁ¿buf //buf Êdz¤¶ÈΪ4£¬ÔªËØÀàÐÍΪ ARRYÀàÐ͵ÄÊý×é //buf Êdz¤¶ÈΪ4£¬ÔªËØÀàÐÍΪ int [3]ÀàÐ͵ÄÊý×é //buf: buf[0] buf[1] buf[2] buf[3]--->int [3] //buf[i] : int [3]ÀàÐÍ£¬---->Êý×éÀàÐÍ //buf[i] : ³¤¶ÈÊÇ3£¬ÔªËØÀàÐÍΪintÀàÐ͵ÄÊý×é //buf[i]µÄÔªËØ£ºbuf[i][0] buf[i][1] buf[i][3] //int buf[4][3]; char str[5][6];
//====================================================== printf("============\n"); printf("%d\n",d); printf("%d\n",*f); printf("%d\n",sizeof(INT)); return 0; } |
¸´ÔÓÊý¾ÝÀàÐ͵Ķ¨Òå
¶¨ÒåÒ»¸ö±äÁ¿µÄʱºò£¬Èç¹û³öÏÖ * £¬ [] £¬ () ·ûºÅµÄʱºò£¬ÐèÒª½«Æäµ±×öÔËËã·û´¦Àí £¬¸ù¾ÝÔËËã·ûµÄÓÅÏȼ¶ºÍ½áºÏÐÔÈ·¶¨±êʶ·û¸úÄǸöÔËËã·ûÓÅÏȽáºÏ
±êʶ·û[] £º Êý×飬----->Êý×éµÄÔªËØÀàÐÍ
È¥µô Êý×éÃû[³¤¶È] ʣϵľÍÊÇÊý×éÔªËØÀàÐÍ
*±êʶ·û £º Ö¸Õë, ------>Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
È¥µô *Ö¸ÕëÃû ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ
±êʶ·û()£º º¯Êý£¬ -----> º¯Êý·µ»ØÖµÀàÐÍ
È¥µô º¯ÊýÃû() ʣϵľÍÊǺ¯ÊýµÄ·µ»ØÖµÀàÐÍ
º¯Êý·µ»ØÖµÀàÐÍ º¯ÊýÃû(²ÎÊýÁбí)
º¯ÊýÀàÐÍ£º º¯Êý·µ»ØÖµÀàÐÍ (²ÎÊýÁбí)
º¯Êý·µ»ØÖµÀàÐÍ£º È¥µô º¯ÊýÃû() ʣϵľÍÊǺ¯ÊýµÄ·µ»ØÖµÀàÐÍ
#include <stdio.h> int main() { char *fun; //*fun, ---->Ö¸Õë //Ö¸ÕëÖ¸ÏòµÄ¶ÔÏóÀàÐÍ char //×Ö·ûÖ¸Õë char fun[10]; //fun[10],---->Êý×é //Êý×éÔªËØÀàÐÍ char char fun[3][4]; //fun[3]½áºÏ£¬---->Êý×é //È¥µô fun[3]£¬Ê£ÏµľÍÊÇÊý×éÔªËصÄÀàÐÍ char [4] //fun: Êdz¤¶ÈΪ3£¬ÔªËØÀàÐÍΪ char [4]ÀàÐ͵ÄÊý×é char *fun[10]; //fun[10]ÓÅÏȽáºÏ£¬--->Êý×é //È¥µôfun[10],ʣϵľÍÊÇÊý×éÔªËصÄÀàÐÍ char * //fun: Êdz¤¶ÈΪ10£¬ÔªËØÀàÐÍΪ char *ÀàÐ͵ÄÊý×é char (*fun)[10]; //*fun ÓÅÏȽáºÏ£¬---->Ö¸Õë //È¥µ½ *fun£¬ ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char [10] //fun £º ÊÇÖ¸Ïò¶ÔÏóÀàÐÍΪÊý×éÀàÐ͵ÄÖ¸Õë //Êý×éÖ¸Õë char *fun(); //fun()ÓÅÏȽáºÏ£¬------>º¯Êý //È¥µô fun(), ʣϵľÍÊǺ¯ÊýµÄ·µ»ØÖµÀàÐÍ char * //º¯Êý·µ»ØµÄÊÇÖ¸Õë //Ö¸Õ뺯Êý char (*fun)(); //*fun ÓÅÏȽáºÏ£¬---->Ö¸Õë //È¥µô *fun,ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char () //fun ÊÇÖ¸Ïò¶ÔÏóΪº¯ÊýÀàÐ͵ÄÖ¸Õë //º¯ÊýÖ¸Õë char **fun; //*fun ÓÅÏȽáºÏ£¬---->Ö¸Õë //È¥µô *fun,ʣϵľÍÊÇÖ¸ÕëÖ¸ÏòµÄ¶ÔÏóµÄÀàÐÍ char * //fun ÊÇÖ¸Ïò¶ÔÏóÀàÐÍΪָÕëÀàÐ͵ÄÖ¸Õë //¶þ¼¶Ö¸Õë } |