Here is a listing of C question bank on “Self Referential Structures” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include -
struct student -
{ -
char *c;
-
struct student *point;
-
};
-
void main()
-
{ -
struct student s;
-
struct student m;
-
s.c = m.c = "hi";
-
m.point = &s;
-
(m.point)->c = "hey";
-
printf("%st%st", s.c, m.c);
-
}
a) hey hi
b) hi hey
c) Run time error
d) hey hey
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include -
struct student -
{ -
char *c;
-
struct student *point;
-
};
-
void main()
-
{ -
struct student s;
-
struct student m;
-
m.point = s;
-
(m.point)->c = "hey";
-
printf("%s", s.c);
-
}
a) Nothing
b) Compile time error
c) hey
d) Varies
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include -
struct student -
{ -
char *c;
-
struct student point;
-
};
-
void main()
-
{ -
struct student s;
-
s.c = "hello";
-
printf("%s", s.c);
-
}
a) hello
b) Nothing
c) Varies
d) Compile time error
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include -
struct student -
{ -
char *c;
-
struct student *point;
-
};
-
void main()
-
{ -
struct student s;
-
printf("%d", sizeof(s));
-
}
a) 5
b) 9
c) 8
d) 16
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include -
struct student -
{ -
char *c;
-
struct student *point;
-
};
-
void main()
-
{ -
struct student s;
-
struct student *m = &s;
-
printf("%d", sizeof(student));
-
}
a) Compile time error
b) 8
c) 5
d) 16
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include -
struct p -
{ -
int x;
-
char y;
-
struct p *ptr;
-
};
-
int main()
-
{ -
struct p p = {1, 2, &p};
-
printf("%dn", p.ptr->x);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) 1
d) 2
Answer: c
Clarification: None.
7. What will be the output of the following C code?
-
#include -
typedef struct p *q;
-
struct p -
{ -
int x;
-
char y;
-
q ptr; -
};
-
int main()
-
{ -
struct p p = {1, 2, &p};
-
printf("%dn", p.ptr->x);
-
return 0;
-
}
a) Compile time error
b) 1
c) Undefined behaviour
d) Address of p
Answer: b
Clarification: None.
8. Presence of loop in a linked list can be tested by ________
a) Traveling the list, if NULL is encountered no loop exists
b) Comparing the address of nodes by address of every other node
c) Comparing the the value stored in a node by a value in every other node
d) None of the mentioned
Answer: b
Clarification: None.
