edited by
19,136 views
41 votes
41 votes

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
edited by

5 Answers

Best answer
58 votes
58 votes

Correct Option: A

$[]$ has greater precedence than $*$ in C. So, $s$ becomes an array of pointers.

edited by
18 votes
18 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.
 

                                    

edited by
14 votes
14 votes

Option A

This is easily solvable by the spiral rule.

http://c-faq.com/decl/spiral.anderson.html


Even complex declarations can be figured out using this.

Source: https://stackoverflow.com/questions/34548762/c-isnt-that-hard-void-f

Answer:

Related questions

52 votes
52 votes
3 answers
2
Kathleen asked Sep 14, 2014
11,745 views
The most appropriate matching for the following pairs$$\begin{array}{|ll|ll|}\hline X: & \text{m = malloc(5); m = NULL;} & 1: & \text{using dangling pointers} \\\hline Y...
29 votes
29 votes
2 answers
3
Kathleen asked Sep 14, 2014
14,919 views
The value of $j$ at the end of the execution of the following C program:int incr (int i) { static int count = 0; count = count + i; return (count); } main () { int i, j; ...
42 votes
42 votes
9 answers
4
Kathleen asked Sep 14, 2014
22,600 views
Aliasing in the context of programming languages refers tomultiple variables having the same memory locationmultiple variables having the same valuemultiple variables hav...