C Programming Questions and Answers – Self-Referential Structures – 1

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

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 student
  3.     {
  4.         char *c;
  5.         struct student *point;
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         struct student m;
  11.         s.c = m.c = "hi";
  12.         m.point = &s;
  13.         (m.point)->c = "hey";
  14.         printf("%s\t%s\t", s.c, m.c);
  15.     }

a) hey hi
b) hi hey
c) Run time error
d) hey hey
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

Note: Join free Sanfoundry classes at Telegram or Youtube
  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.         struct student *point;
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         struct student m;
  11.         m.point = s;
  12.         (m.point)->c = "hey";
  13.         printf("%s", s.c);
  14.     }

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

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.         struct student point;
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.c = "hello";
  11.         printf("%s", s.c);
  12.     }

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

Answer: d
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.         struct student *point;
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         printf("%d", sizeof(s));
  11.     }

a) 5
b) 9
c) 8
d) 16
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.         struct student *point;
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         struct student *m = &s;
  11.         printf("%d", sizeof(student));
  12.     }

a) Compile time error
b) 8
c) 5
d) 16
View Answer

Answer: a
Explanation: None.

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

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

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

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     typedef struct p *q;
  3.     struct p
  4.     {
  5.         int x;
  6.         char y;
  7.         q ptr;
  8.     };
  9.     int main()
  10.     {
  11.         struct p p = {1, 2, &p};
  12.         printf("%d\n", p.ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) 1
c) Undefined behaviour
d) Address of p
View Answer

Answer: b
Explanation: None.

8. Presence of loop in a linked list can be tested by ________
a) Traveling the list, if NULL is encountered no loop exists
b) Comparing the address of nodes by address of every other node
c) Comparing the the value stored in a node by a value in every other node
d) None of the mentioned
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.

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.