Home > Software engineering >  I am unable to understand what is the statement struct node *a [26] used for.. after we make the str
I am unable to understand what is the statement struct node *a [26] used for.. after we make the str

Time:01-06

struct node{
     int data;
     struct node*next;
};
struct node * a[26];

Are we making an array of node pointers or assigning size to the node pointer? Please help me out I am stuck with this problem.

CodePudding user response:

struct node * a[26]; declares a to be an array of 26 pointers to struct node.

CodePudding user response:

This declaration

struct node * a[26];

declares an array with name a with 26 elements of the pointer type struct node *.

These two declarations

struct node{
     int data;
     struct node*next;
};
struct node * a[26];

also may be rewritten as one declaration the following way

struct node{
     int data;
     struct node*next;
} * a[26];

CodePudding user response:

struct node * a[26];

Let's examine it step by step:

A realistic way of reading declarations in C is boustrophedonically, i.e. alternating right to left and left to right, starting from the first identifier when reading from the left until we a see a semi-colon, a bracket or reach the end of the left side.

a[26];

declares an array of 26 elements. We see a semi-colon so we go back to the left:

* a[26];

This becomes an array of 26 pointers. We continue to the left because we haven't reached the end yet.

struct node * a[26];

This becomes an array of 26 pointers to an object of type struct node.

In a nutshell, a is an array of 26 pointers to an object of type struct node.

NB that the actual rules are determined by the formal grammar and mirror operator precedence, as stated in the comment below.

  • Related