Error “initializer element is not constant” when allocate the memory

后端 未结 4 1552
遥遥无期
遥遥无期 2020-12-11 05:13
  1 #include
  2 #include
  3 
  4 typedef struct node_t{
  5     int i;
  6     struct node_t* link;
  7 }node;
  8 
  9 node* head =         


        
4条回答
  •  情歌与酒
    2020-12-11 05:14

    head is a global varibale. Global and static varibales must be initialized by constant expressions, i.e. literals. so you can't do

    node* head = (node *)malloc(sizeof(node));
    

提交回复
热议问题