How to create a struct on the stack in C?

后端 未结 4 1790
遇见更好的自我
遇见更好的自我 2020-12-23 19:18

I understand how to create a struct on the heap using malloc. Was looking for some documentation regarding creating a struct in C on t

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 20:03

    The same way you declare any variable on the stack:

    struct my_struct {...};
    
    int main(int argc, char **argv)
    {
        struct my_struct my_variable;     // Declare struct on stack
        .
        .
        .
    }
    

提交回复
热议问题