What is a self referential structures in C

1 Answer

0 votes
// A self referential structure is a structure containing the same structure pointer variable.
// A self referential structure used to create data structures like linked lists, binary trees,..

#include <stdio.h>

struct test
{
    int n;
    struct test *p;
}; 

int main(void)
{
    struct test t;
    
    t.n = 13;
    t.p = &t;
    
    printf("t.p->n = %d\n", t.p->n);
  
    return 0;
}

  
/*
run:
  
t.p->n = 13

*/

 



answered Jun 21, 2017 by avibootz
...