in Programming edited by
11,160 views
33 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
in Programming edited by
11.2k views

Subscribe to GO Classes for GATE CSE 2022

5 Answers

49 votes
 
Best answer

Correct Option: A

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

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

2 Comments

Nice one
0
Never came across with this! thanks :)
0
2 votes
Ans: A An array, each element of which is a pointer to a structure of type node
2 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

 

Answer:

Related questions

Ask
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