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.
1. What will be the output of the following C code?
#include <stdio.h>
typedef struct p *q;
int main()
{
struct p
{
int x;
char y;
q ptr;
};
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->x);
return 0;
}
a) Compile time error
b) 1
c) Depends on the compiler
d) None of the mentioned
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
typedef struct p *q;
struct p
{
int x;
char y;
q ptr;
};
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->x);
return 0;
}
a) Compile time error
b) 1
c) Depends on the compiler
d) Depends on the standard
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
typedef struct p *q;
struct p
{
int x;
char y;
q ptr;
};
int main()
{
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->ptr->x);
return 0;
}
a) Compile time error
b) Segmenation fault
c) Undefined behaviour
d) 1
View Answer
Explanation: None.
4. The number of distinct nodes the following struct declaration can point to is _____________
struct node
{
struct node *left;
struct node *centre;
struct node *right;
};
a) 1
b) 2
c) 3
d) All of the mentioned
View Answer
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
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
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?
struct node
{
struct node *next;
};
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
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]
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Check C Books
- Apply for C Internship
- Check Computer Science Books