Thread: Structure within structure

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    81

    Structure within structure

    I understand the declaration of pointer and structure in c programming

    Declaration of integer pointer
    Code:
     /*declaration of integer pointer*/
    int *next;
    Declaration of structure
    Code:
     /*declaration of structure*/struct student 
    {
        int id;
        char name[20];
     
    }profile;
    I'm confused with following declaration

    Code:
    struct student {   
      struct student *next;
    }profile;
    here student is name of structure and next is pointer variable

    What is meaning of following line
    Code:
     struct student *next;

  2. #2
    Guest
    Guest
    That line just means:
    Code:
    student *next;
    But in C you have to specify the structness of the type to help the compiler. In C++ you wouldn't.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    This would be a struct for a node in a linked list data structure, where the pointer "next" in one node would point to the next node in the list, or be set to NULL if this is the only, or last node in the list.

    Please see a description of a linked list here, or Google it for more detailed and extensive tutorials on single and double linked lists.

    You might want to study further topics in Data Structures and Algorithms in C. A simple Google search will yield many links to online tutorials, books and PDF files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-04-2017, 07:42 AM
  2. Replies: 10
    Last Post: 03-18-2014, 10:43 AM
  3. Replies: 4
    Last Post: 04-25-2010, 10:57 AM
  4. Replies: 9
    Last Post: 05-21-2007, 12:10 AM

Tags for this Thread