C Programming Questions and Answers – Structures and Functions – 2

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

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

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     int main()
  8.     {
  9.         struct point p = {1};
  10.         struct point p1 = {1};
  11.         if(p == p1)
  12.             printf("equal\n");
  13.         else
  14.             printf("not equal\n");
  15.     }

a) Compile time error
b) equal
c) depends on the standard
d) not equal
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     struct point foo();
  13.     int main()
  14.     {
  15.         struct point p = {1};
  16.         struct notpoint p1 = {2, 3};
  17.         p1 = foo();
  18.         printf("%d\n", p1.x);
  19.     }
  20.     struct point foo()
  21.     {
  22.         struct point temp = {1, 2};
  23.         return temp;
  24.     }

a) Compile time error
b) 1
c) 2
d) Undefined behaviour
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     int main()
  13.     {
  14.         struct point p = {1};
  15.         struct notpoint p1 = p;
  16.         printf("%d\n", p1.x);
  17.     }

a) Compile time error
b) 1
c) 0
d) Undefined
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     void foo(struct point);
  13.     int main()
  14.     {
  15.         struct notpoint p1 = {1, 2};
  16.         foo(p1);
  17.     }
  18.     void foo(struct point p)
  19.     {
  20.         printf("%d\n", p.x);
  21.     }

a) Compile time error
b) 1
c) 0
d) Undefined
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1 = {1, 2};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%d\n", *p.x++);
  16.     }

a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1 = {1, 2};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%d\n", *p->x++);
  16.     }

a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct student fun(void)
  3.     {
  4.         struct student
  5.         {
  6.             char *name;
  7.         };
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         printf("%s", m.name);
  16.     }

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

Answer: a
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.         printf("%s", m.name);
  16.     }

a) Nothing
b) alan
c) Run time error
d) Varies
View Answer

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