250+ TOP MCQs on Self-Referential Structures and Answers

C Objective Questions on “Self-Referential Structures”. One shall practice these Objective 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 Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Self-Referential Structures” along with answers, explanations and/or solutions:

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

  1.     #include 
  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("%dn", p.ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) 1
c) Depends on the compiler
d) None of the mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  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("%dn", p.ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) 1
c) Depends on the compiler
d) Depends on the standard
Answer: b
Clarification: None.

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

  1.     #include 
  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("%dn", p.ptr->ptr->x);
  13.         return 0;
  14.     }

a) Compile time error
b) Segmenation fault
c) Undefined behaviour
d) 1
Answer: d
Clarification: None.

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

  250+ TOP MCQs on Command Line Arguments and Answers

Leave a Comment

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

Scroll to Top