Home
Questions
Search
Forum
Contact
Guest Book
Polls!
Got a Question?
 
PREV
Linked Lists
NEXT
 
(4 / 301)
 
 



How to declare a structure of a linked list?




The right way of declaring a structure for a linked list in a C program is


struct node {
  int value;
  struct node *next;
};
typedef struct node *mynode;


Note that the following are not correct


typedef struct {
  int value;
  mynode next;
} *mynode;


The typedef is not defined at the point where the "next" field is declared.



struct node {
  int value;
  struct node next;
};
typedef struct node mynode;


You can only have pointer to structures, not the structure itself as its recursive!


PREV
COMMENTS                                  INDEX                                  PRINT
NEXT



Last updated: November 3, 2005

www.cracktheinterview.com - Your destination for the most common IT interview questions, answers, frequently asked interview questions (FAQ), C Programs, C Datastructures for technical interviews conducted by the top IT companies around the world!