Chad said:
Quote:
Given the following.....
>
#include <stdlib.h>
#include <stdio.h>
>
struct node {
int data;
struct node *next;
};
>
int main(void)
{
struct node* head;
>
head = malloc(sizeof(struct node));
Better: head = malloc(sizeof *head);
Don't assume malloc succeeded - *check* that it succeeded, and take
appropriate action if it failed.
Quote:
head->data = 1;
head->next = NULL;
>
head = head->next;
>
free(head);
>
return 0;
}
>
>
Is struct node *next defintion or declaration?
It's part of a type definition. The grammar calls it a declarator:
struct-or-union-specifier:
struct-or-union identifier<opt{
struct-declaration-list }
struct-or-union identifier
struct-or-union:
struct
union
struct-declaration-list:
struct-declaration
struct-declaration-list struct-declaration
struct-declaration:
specifier-qualifier-list struct-declarator-list ;
specifier-qualifier-list:
type-specifier specifier-qualifier-list<opt>
type-qualifier specifier-qualifier-list<opt>
struct-declarator-list:
struct-declarator
struct-declarator-list , struct-declarator
struct-declarator:
declarator
declarator<opt: constant-expression
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999