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

«
»

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

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.     typedef struct p *q;
  3.     int main()
  4.     {
  5.         struct p
  6.         {
  7.             int x;
  8.             char y;
  9.             q ptr;
  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) Depends on the compiler
d) None of the mentioned
View Answer

Answer: a
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         typedef struct p *q;
  5.         struct p
  6.         {
  7.             int x;
  8.             char y;
  9.             q ptr;
  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) Depends on the compiler
d) Depends on the standard
View Answer

Answer: b
Explanation: None.
advertisement

3. 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->ptr->x);
  13.         return 0;
  14.     }

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

Answer: d
Explanation: None.
advertisement

4. The number of distinct nodes the following struct declaration can point to is _____________

  1.     struct node
  2.     {
  3.         struct node *left;
  4.         struct node *centre;
  5.         struct node *right;
  6.     };

a) 1
b) 2
c) 3
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

5. Which of the following is not possible regarding the structure variable?
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other
d) None of the mentioned
View Answer

Answer: d
Explanation: None.

6. Which of the following technique is faster for travelling in binary trees?
a) Iteration
b) Recursion
c) Both Iteration and Recursion
d) Depends from compiler to compiler
View Answer

Answer: b
Explanation: None.

7. Which of the following will stop the loop at the last node of a linked list in the following C code snippet?

  1.     struct node
  2.     {
  3.         struct node *next;
  4.     };

a)

    while (p != NULL)
    {
        p = p->next;
    }

b)

    while (p->next != NULL)
    {
        p = p->next;
    }

c)

    while (1)
    {
        p = p->next;
        if (p == NULL)
            break;
    }

d) All 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.

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.