C Programming Questions and Answers – Basics of Structures – 2

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

Pre-requisite for C Structure MCQ set: C Video Tutorial on Structures.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         no = 8;
  11.         printf("%d", no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

2. How many bytes in memory taken by the following C structure?

  1.     #include <stdio.h>
  2.     struct test
  3.     {
  4.         int k;
  5.         char c;
  6.     };

a) Multiple of integer size
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct
  3.     {
  4.         int k;
  5.         char c;
  6.     };
  7.     int main()
  8.     {
  9.         struct p;
  10.         p.k = 10;
  11.         printf("%d\n", p.k);
  12.     }

a) Compile time error
b) 10
c) Undefined behaviour
d) Segmentation fault
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct
  3.     {
  4.         int k;
  5.         char c;
  6.     } p;
  7.     int p = 10;
  8.     int main()
  9.     {
  10.         p.k = 10;
  11.         printf("%d %d\n", p.k, p);
  12.     }

a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.     };
  7.     int p = 10;
  8.     int main()
  9.     {
  10.         struct p x;
  11.         x.k = 10;
  12.         printf("%d %d\n", x.k, p);
  13.     }

a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int p = 10;
  9.     int main()
  10.     {
  11.         struct p x = {1, 97};
  12.         printf("%f %d\n", x.f, p);
  13.     }

a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
View Answer

Answer: b
Explanation: None.

7. What will be the output of the following C code according to C99 standard?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97, .f = 3, .k = 1};
  11.         printf("%f\n", x.f);
  12.     }

a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
View Answer

Answer: a
Explanation: None.

8. What will be the output of the following C code according to C99 standard?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97, .k = 1, 3};
  11.         printf("%f \n", x.f);
  12.     }

a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
View Answer

Answer: b
Explanation: None.

9. What will be the output of the following C code according to C99 standard?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97};
  11.         printf("%f\n", x.f);
  12.     }

a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
View Answer

Answer: a
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
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 & discussions at Telegram SanfoundryClasses.