The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
1.5k 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 (59.6k points)
edited by | 1.5k views

4 Answers

+36 votes
Best answer

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

answered by Boss (18.3k points)
edited by
+8 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 Active (2.2k points)
edited by
+2 votes
Ans: A An array, each element of which is a pointer to a structure of type node
answered by Loyal (7.5k points)
0 votes

the answer would be the option a because 

 

struct node 

s[10]---------------> precedence 1---------------------> array 

*  -------------------> precedence 2--------------------->pointer 

now according to precedence, we can say

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

 

 

 

http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm

 

answered by Active (3.9k points)
Answer:

Related questions



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

42,579 questions
48,568 answers
155,478 comments
63,600 users