c - Initializer element is not constant -
this question has answer here:
i'm trying declare dummy head*
global variable ide giving error:
initializer element not constant
how fix that?
typedef struct mynode{ struct mynode *next; int value; }node; //declare global variable node *head = malloc(sizeof(node)); head->next = null;
the obvious thing declare head variable global initialisation within function.
typedef struct mynode{ struct mynode *next; int value; } node; node *head; int main (int argc, char **argv) { head = malloc(sizeof *head); if (!head) { /* error */ exit(-1); } head->next = null; return 0; }
Comments
Post a Comment