Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Structs program in C

I'm new to programming so please bear with me. Can anyone please explain what the last line of code is doing and what this entire block of code trying to do. I know the first block is creating a structure called node and adding two pointers *next and *prev to it. btw this is a part of a linked list program

struct node
 {
  char line[80];
  struct node *next,*prev;
 };

struct node *start=NULL,*temp,*temp1,*temp2,*newnode;

Thank you in advance.

like image 351
Shy Student Avatar asked Dec 09 '22 16:12

Shy Student


2 Answers

struct node *start=NULL,*temp,*temp1,*temp2,*newnode;

can be as

struct node *start=NULL;
struct node  *temp;
struct node *temp1;
struct node *temp2;
struct node *newnode;

Now is it easy to understand..?

like image 161
Jeegar Patel Avatar answered Dec 20 '22 09:12

Jeegar Patel


The last line is creating 5 pointers of type struct node namely start which is pointing to NULL, temp, temp1, temp2 and newnode.

The whole block of code is actually creating a struct called node which contains an array of 80 characters, followed by pointers to next and previous. Hence it is creating a structure for a doubly linked list.

like image 45
Aniket Inge Avatar answered Dec 20 '22 08:12

Aniket Inge