250+ TOP MCQs on Structures and Functions and Answers

C programming questions on “Structures and Functions”. One shall practice these 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 programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming questions on “Structures and Functions” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s;
  7.     struct student fun(void)
  8.     {
  9.         s.name = "newton";
  10.         printf("%sn", s.name);
  11.         s.name = "alan";
  12.         return s;
  13.     }
  14.     void main()
  15.     {
  16.         struct student m = fun();
  17.         printf("%sn", m.name);
  18.         m.name = "turing";
  19.         printf("%sn", s.name);
  20.     }

a) newton alan alan
b) alan newton alan
c) alan alan newton
d) compile time error
Answer: a
Clarification: None.

2. 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, 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
Answer: d
Clarification: None.

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
Answer: d
Clarification: None.

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

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

a) 10 (Garbage Value)
b) 0 10
c) 10 0
d) (Garbage Value) 10
Answer: c
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: 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
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.     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
Answer: c
Clarification: None.

  250+ TOP MCQs on Endianness and Answers

Leave a Comment

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

Scroll to Top