250+ TOP MCQs on Arrays of Structures and Answers

C Objective Questions on “Arrays of Structures”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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.

  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.         int b;
  6.         int c;
  7.     };
  8.     main()
  9.     {
  10.         struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
  11.     }

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)

  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.         int b;
  6.         int c;
  7.     } p[] = {0};
  8.     main()
  9.     {
  10.         printf("%d", sizeof(p));
  11.     }

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?

  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s[2];
  7.     void main()
  8.     {
  9.         s[0].name = "alan";
  10.         s[1] = s[0];
  11.         printf("%s%s", s[0].name, s[1].name);
  12.         s[1].name = "turing";
  13.         printf("%s%s", s[0].name, s[1].name);
  14.     }

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?

  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s[2], r[2];
  7.     void main()
  8.     {
  9.         s[0].name = "alan";
  10.         s[1] = s[0];
  11.         r = s;
  12.         printf("%s%s", r[0].name, r[1].name);
  13.     }

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?

  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     void main()
  7.     {
  8.         struct student s[2], r[2];
  9.         s[1] = s[0] = "alan";
  10.         printf("%s%s", s[0].name, s[1].name);
  11.     }

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?

  1.     #include 
  2.     struct student
  3.     {
  4.     };
  5.     void main()
  6.     {
  7.         struct student s[2];
  8.         printf("%d", sizeof(s));
  9.     }

a) 2
b) 4
c) 8
d) 0
Answer: d
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *