C Programming Questions and Answers on Self-Referential Structures for Freshers

1. What is the output of this 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("%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
Answer: a
2. What is the output of this 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("%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
Answer: b
3. What is the output of this 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("%d\n", p.ptr->ptr->x);
  13.         return 0;
  14.     }
a) Compile time error
b) Segmenation fault
c) Undefined behaviour
d) 1
Answer: d
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
5. Which of the following is not possible?

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
6. Which of the following techinique is faster for travelling in binary trees?

a) Iteration
b) Recursion
c) Both Iteration and Recursion
d) Depends from compiler to compiler
Answer: b
7. For the following declaration of structure, which of the following will stop the loop at the last node of a linked list?
  1.     struct node
  2.     {
  3.         struct node *next;
  4.     };
  1. a) while (p != NULL)
  2.     {
  3.         p = p->next;
  4.     }
  5. b) while (p->next != NULL)
  6.     {
  7.         p = p->next;
  8.     }
  9. c) while (1)
  10.     {
  11.         p = p->next;
  12.         if (p == NULL)
  13.             break;
  14.     }
  15. d) All of the mentioned

Answer: b
8. What is the output of this C code?
  1.     #include 
  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
Answer: a
9. What is the output of this C code?
  1.     #include 
  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
Answer: b
10. What is the output of this C code?
  1.     #include 
  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
Answer: d
11. What is the output of this C code?
  1.     #include 
  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
Answer: c
12. What is the output of this C code?
  1.     #include 
  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
Answer: a
13. What is the output of this C code?
  1.     #include 
  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
Answer: c
14. What is the output of this C code?
  1.     #include 
  2.     typedef struct p *q;
  3.     struct p
  4.     {
  5.         int x;
  6.         char y;
  7.         q ptr;
  8.     };
  9.     typedef struct p *q;
  10.     int main()
  11.     {
  12.         struct p p = {1, 2, &p};
  13.         printf("%d\n", p.ptr->x);
  14.         return 0;
  15.     }
a) Compile time error
b) 1
c) Undefined behaviour
d) Address of p
Answer: a

Related

Data Structure Objective Type Questions and Answers on Circular Linked List

1. What differentiates a circular linked list from a normal linked list? a) You cannot have the ‘next’ pointer point to null in a circular linked listb) It is faster to traverse the circular linked...

Data Structure Multiple Choice Questions and Answers on Single Linked List Operations

1. A linear collection of data elements where the linear node is given by means of pointer is called? a) Linked listb) Node listc) Primitive listd) None of the mentioned Answer: a 2. Consider an ...

Data Structure Multiple Choice Questions and Answers on Queue Operations

1. A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a ? a) Queueb) Stackc) Treed) Linked list Answ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item