The following C declarations: struct node { int i; float j; }; struct node…

2000

The following C declarations:

struct node {
int i;
float j;
};
struct node *s[10];

define s to be:

  1. A.

    An array, each element of which is a pointer to a structure of type node

  2. B.

    A structure of 2 fields, each field being a pointer to an array of 10 elements

  3. C.

    A structure of 3 fields: an integer, a float, and an array of 10 elements

  4. D.

    An array, each element of which is a structure of type node.

Attempted by 65 students.

Show answer & explanation

Correct answer: A

The correct answer is: An array, each element of which is a pointer to a structure of type node.

Read the declaration from the identifier outward. In struct node *s[10], the brackets [] bind more tightly than the unary * in a declaration. So s[10] means s is an array of 10 elements.

The remaining part, struct node *, says that each element of the array is a pointer to struct node.

Therefore, s is an array of 10 pointers to structures of type node, not an array of structures and not a structure with extra fields.

Explore the full course: Gate Guidance By Sanchit Sir