Allocation of memory for char array

前端 未结 10 812
孤独总比滥情好
孤独总比滥情好 2021-01-02 12:45

Let\'s say you have-

struct Person {
    char *name;
    int age;
    int height;
    int weight; 
 };

If you do-

struct Pe         


        
10条回答
  •  鱼传尺愫
    2021-01-02 13:24

    You have a pointer to a name character array in your struct, ie. it will consume that much bytes that are needed to represent a memory address.

    If you want to actually use the field, you must allocate additional memory for it.

提交回复
热议问题