From the C99 standard:
6.7.8 Initialization
Constraints
4 All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.
Hence,
Node *head = malloc(sizeof(Node));
is not allowed. You can initialize head
with a constant expression, such as NULL.
Node *head = NULL;
Of course, statements like:
head->next = NULL;
are not allowed outside functions. Hence, proper initialization of head
has to be done in a function. One way to do that would be:
Node* head = NULL;
Node* createNode()
{
Node* node = malloc(sizeof(*node));
node->value = 0;
node->next = NULL;
return node;
}
int main()
{
head = createNode();
...
}