📅  最后修改于: 2023-12-03 15:28:44.550000             🧑  作者: Mango
The question number 45 from the GATE-CS-2016 (Set 1) paper pertains to programming and is as follows:
Given the following declarations in C:
struct node {
int i;
float j;
};
struct node *s[10];
Which one of the following is correct in reference to the above declarations?
(a) s is a pointer to an array of 10 structures (b) s is an array of 10 structures, each of which is a pointer to an int and a float (c) s is an array of 10 pointers to structures, each of which has an int member and a float member (d) s is an array of 10 pointers to structures, each of which points to an int and a float
The correct answer is (c).
The above C code declares a structure node
which has two members, an integer i
and a float j
. It then declares an array s
of 10 pointers to structures of type node
.
Option (a) is incorrect because s
is not a pointer to an array of structures, but is instead an array of pointers to structures.
Option (b) is incorrect because it suggests that each structure in the array s
is a pointer to an int and a float. This is not the case - each element of the array s
is a pointer to a structure of type node
, which contains an int and a float.
Option (c) is correct because it correctly characterizes s
as an array of pointers to structures, where each structure has a member i
of type int and a member j
of type float.
Option (d) is incorrect because it suggests that each element of the array s
points to an int and a float - this is not the case, as each element of s
is a pointer to a structure of type node
, which contains an int and a float.
# GATE-CS-2016 (Set 1) - Question 45
The question number 45 from the GATE-CS-2016 (Set 1) paper pertains to programming and is as follows:
Given the following declarations in C:
struct node { int i; float j; }; struct node *s[10];
Which one of the following is correct in reference to the above declarations?
(a) s is a pointer to an array of 10 structures
(b) s is an array of 10 structures, each of which is a pointer to an int and a float
(c) s is an array of 10 pointers to structures, each of which has an int member and a float member
(d) s is an array of 10 pointers to structures, each of which points to an int and a float
The correct answer is (c).
### Explanation
The above C code declares a structure `node` which has two members, an integer `i` and a float `j`. It then declares an array `s` of 10 pointers to structures of type `node`.
Option (a) is incorrect because `s` is not a pointer to an array of structures, but is instead an array of pointers to structures.
Option (b) is incorrect because it suggests that each structure in the array `s` is a pointer to an int and a float. This is not the case - each *element* of the array `s` is a pointer to a structure of type `node`, which contains an int and a float.
Option (c) is correct because it correctly characterizes `s` as an array of pointers to structures, where each structure has a member `i` of type int and a member `j` of type float.
Option (d) is incorrect because it suggests that each element of the array `s` points to an int and a float - this is not the case, as each element of `s` is a pointer to a structure of type `node`, which contains an int and a float.