C Programming Questions and Answers – Structures and Functions – 1

«
»

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

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

advertisement

1. 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;
  7.     struct student fun(void)
  8.     {
  9.         s.name = "newton";
  10.         printf("%s\n", s.name);
  11.         s.name = "alan";
  12.         return s;
  13.     }
  14.     void main()
  15.     {
  16.         struct student m = fun();
  17.         printf("%s\n", m.name);
  18.         m.name = "turing";
  19.         printf("%s\n", s.name);
  20.     }

a) newton alan alan
b) alan newton alan
c) alan alan newton
d) compile time error
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

Participate in C Programming Certification Contest of the Month Now!
advertisement
  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     void main()
  7.     {
  8.         struct student s, m;
  9.         s.name = "st";
  10.         m = s;
  11.         printf("%s%s", s.name, m.name);
  12.     }

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

Answer: d
Explanation: None.
advertisement

3. Which of the following return-type cannot be used for a function in C?
a) char *
b) struct
c) void
d) none of the mentioned
View Answer

Answer: d
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  2.     struct temp
  3.     {
  4.         int a;
  5.     } s;
  6.     void func(struct temp s)
  7.     {
  8.         s.a = 10;
  9.         printf("%d\t", s.a);
  10.     }
  11.     main()
  12.     {
  13.         func(s);
  14.         printf("%d\t", s.a);
  15.     }

a) 10 (Garbage Value)
b) 0 10
c) 10 0
d) (Garbage Value) 10
View Answer

Answer: c
Explanation: None.

5. Which of the following is not possible under any scenario?
a) s1 = &s2;
b) s1 = s2;
c) (*s1).number = 10;
d) None of the mentioned
View Answer

Answer: d
Explanation: None.

6. Which of the following operation is illegal in structures?
a) Typecasting of structure
b) Pointer to a variable of the same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
View Answer

Answer: a
Explanation: None.

7. Presence of code like “s.t.b = 10” indicates __________
a) Syntax Error
b) Structure
c) double data type
d) An ordinary variable name
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.     struct student fun(void)
  7.     {
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         s.name = "turing";
  16.         printf("%s", m.name);
  17.     }

a) alan
b) Turing
c) Compile time error
d) Nothing
View Answer

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