Can I name a variable with the same name as a typedef'd structure name?

后端 未结 5 1051
北荒
北荒 2020-12-20 14:14

Here is the structure declare code.

struct list_el {
    int val;
    struct list_el * next;
};

typedef struct list_el item;

And when I

5条回答
  •  半阙折子戏
    2020-12-20 15:01

    typedef is not completely same as #define

    Here is the difference by example:

    #define cptr1 char*
    
    typedef char* cptr2;
    

    In code:

               int main()
                {
                 cptr1 c1,c2; // first case : 
            // here c1 will be pointer to char but c2 is only char as cptr 
       // is directly replaced by char* by preprocessor
                cptr2 c3,c4; // second case :
          // here c3 and c4 both are pointers to char 
                }
    

提交回复
热议问题