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

4 Answers

+33 votes
Best answer

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

answered by Boss (18k points)
edited by
+7 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.1k 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.1k 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 ago by Active (3.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

37,118 questions
44,701 answers
127,278 comments
43,765 users