How to create a new instance of a struct

后端 未结 3 477
独厮守ぢ
独厮守ぢ 2021-01-01 16:50

What is the correct way to create a new instance of a struct? Given the struct:

struct listitem {
    int val;
    char * def;
    struct listitem * next;
};
         


        
3条回答
  •  抹茶落季
    2021-01-01 17:25

    struct listitem newItem; // Automatic allocation
    newItem.val = 5;
    

    Here's a quick rundown on structs: http://www.cs.usfca.edu/~wolber/SoftwareDev/C/CStructs.htm

提交回复
热议问题