The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
896 views

The following C declarations

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

define s to be

  1. An array, each element of which is a pointer to a structure of type node
  2. A structure of $2$ fields, each field being a pointer to an array of $10$ elements
  3. A structure of $3$ fields: an integer, a float, and an array of $10$ elements
  4. An array, each element of which is a structure of type node
asked in Programming by Veteran (68.8k points)
edited ago by | 896 views

3 Answers

+32 votes
Best answer

(A) is the answer. $[]$ has greater precedence than $*$ in C. So, $s$ becomes an array of pointers.

answered by Veteran (14.6k points)
edited ago by
+6 votes

The reference id from *s[10] to the structure and not vice-versa, ruling out options B & C.
The main ambiguity lies among options A & D.
Declaration of the type : struct node s[10] == option D.
*s[10] is an array of 10 pointers, each of type struct node. Hence, option A is the correct answer.
The precedence among operators * & [] can also be another determining factor.
 

 

                                    

answered by Boss (8.6k points)
edited by
+2 votes
Ans: A An array, each element of which is a pointer to a structure of type node
answered by Boss (7.4k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

32,442 questions
39,188 answers
108,794 comments
36,561 users