C Programming Questions and Answers – Arrays of Structures – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Arrays of Structures – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

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;
View Answer

Answer: d
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

2. Comment on the output of the following C code.

advertisement
  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.
advertisement

3. Which of the following uses structure?
a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: None.
advertisement

5. What will be the output of the following C code? (Assuming size of int be 4)

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

9. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.