Here is a listing of C Objective Questions on “Arrays of Structures” along with answers, explanations and/or solutions:
1. The correct syntax to access the member of the ith structure in the array of structures is?
Assuming: struct temp { int b; }s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
Answer: d
Clarification: None.
2. Comment on the output of the following C code.
-
#include
-
struct temp
-
{
-
int a;
-
int b;
-
int c;
-
};
-
main()
-
{
-
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
-
}
a) No Compile time error, generates an array of structure of size 3
b) No Compile time error, generates an array of structure of size 9
c) Compile time error, illegal declaration of a multidimensional array
d) Compile time error, illegal assignment to members of structure
Answer: a
Clarification: None.
3. Which of the following uses structure?
a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned
Answer: d
Clarification: None.
4. What is the correct syntax to declare a function foo() which receives an array of structure in function?
a) void foo(struct *var);
b) void foo(struct *var[]);
c) void foo(struct var);
d) none of the mentioned
Answer: a
Clarification: None.
5. What will be the output of the following C code? (Assuming size of int be 4)
-
#include
-
struct temp
-
{
-
int a;
-
int b;
-
int c;
-
} p[] = {0};
-
main()
-
{
-
printf("%d", sizeof(p));
-
}
a) 4
b) 12
c) 16
d) Can’t be estimated due to ambiguous initialization of array
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
char *name;
-
};
-
struct student s[2];
-
void main()
-
{
-
s[0].name = "alan";
-
s[1] = s[0];
-
printf("%s%s", s[0].name, s[1].name);
-
s[1].name = "turing";
-
printf("%s%s", s[0].name, s[1].name);
-
}
a) alan alan alan turing
b) alan alan turing turing
c) alan turing alan turing
d) run time error
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
char *name;
-
};
-
struct student s[2], r[2];
-
void main()
-
{
-
s[0].name = "alan";
-
s[1] = s[0];
-
r = s;
-
printf("%s%s", r[0].name, r[1].name);
-
}
a) alan alan
b) Compile time error
c) Varies
d) Nothing
Answer: b
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
char *name;
-
};
-
void main()
-
{
-
struct student s[2], r[2];
-
s[1] = s[0] = "alan";
-
printf("%s%s", s[0].name, s[1].name);
-
}
a) alan alan
b) Nothing
c) Compile time error
d) Varies
Answer: c
Clarification: None.
9. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
};
-
void main()
-
{
-
struct student s[2];
-
printf("%d", sizeof(s));
-
}
a) 2
b) 4
c) 8
d) 0
Answer: d
Clarification: None.