Here is a listing of online C quiz on “Table Lookup” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
char a[5];
-
};
-
void main()
-
{
-
struct student s[] = {"hi", "hey"};
-
printf("%c", s[0].a[1]);
-
}
a) h
b) i
c) e
d) y
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
char *a[3] = {"hello", "this"};
-
printf("%s", a[1]);
-
}
a) hello
b) Varies
c) this
d) Compile time error
Answer: c
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-
printf("%d", lookup[3]);
-
}
a) 2
b) 4
c) Compile time error
d) 3
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
-
, {"hellos", "hi's", "hmm"}};
-
printf("%s", a[1][1]);
-
}
a) her
b) hi
c) Compile time error
d) hi’s
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
struct p
-
{
-
char *name;
-
struct p *next;
-
};
-
struct p *ptrary[10];
-
int main()
-
{
-
struct p p;
-
p->name = "xyz";
-
p->next = NULL;
-
ptrary[0] = &p;
-
printf("%sn", p->name);
-
return 0;
-
}
a) Compile time error
b) Segmentation fault/code crash
c) xyz
d) Undefined behaviour
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
struct p
-
{
-
char *name;
-
struct p *next;
-
};
-
struct p *ptrary[10];
-
int main()
-
{
-
struct p p;
-
p.name = "xyz";
-
p.next = NULL;
-
ptrary[0] = &p;
-
printf("%sn", ptrary[0]->name);
-
return 0;
-
}
a) Compile time error
b) Segmentation fault
c) Undefined behaviour
d) xyz
Answer: d
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
struct p
-
{
-
char *name;
-
struct p *next;
-
};
-
struct p *ptrary[10];
-
int main()
-
{
-
struct p p, q;
-
p.name = "xyz";
-
p.next = NULL;
-
ptrary[0] = &p;
-
strcpy(q.name, p.name);
-
ptrary[1] = &q;
-
printf("%sn", ptrary[1]->name);
-
return 0;
-
}
a) Compile time error
b) Segmentation fault/code crash
c) Depends on the compiler
d) xyz
Answer: b
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
struct p
-
{
-
char *name;
-
struct p *next;
-
};
-
struct p p, q;
-
p.name = "xyz";
-
p.next = NULL;
-
ptrary[0] = &p;
-
strcpy(q.name, p.name);
-
ptrary[1] = &q;
-
printf("%sn", ptrary[1]->name);
-
return 0;
-
}
a) Compile time error
b) Depends on the compiler
c) Undefined behaviour
d) xyz
Answer: c
Clarification: None.