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.
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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.