The following C declarations:
struct node {
int i:
float j;
};
struct node *s[10];
define s to be:
View worked solution
Answer: A
To understand the declaration struct node *s[10];, we analyze the precedence of operators in C:
- The array subscript operator
[]has higher precedence than the pointer dereference operator*. - As a result, the identifier
sassociates first with[10], makingsan array of 10 elements. - The prefix
struct node *specifies the type of these elements, which is a pointer tostruct node.
Therefore, s is an array, each element of which is a pointer to a structure of type node.
Free practice · Your answers on this page are not saved.
