This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Table Lookup – 1”.
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>
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
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[3] = {"hello", "this"};
printf("%s", a[1]);
}
a) hello
b) Varies
c) this
d) Compile time error
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
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("%s\n", p->name);
return 0;
}
a) Compile time error
b) Segmentation fault/code crash
c) xyz
d) Undefined behaviour
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
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("%s\n", ptrary[0]->name);
return 0;
}
a) Compile time error
b) Segmentation fault
c) Undefined behaviour
d) xyz
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
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("%s\n", ptrary[1]->name);
return 0;
}
a) Compile time error
b) Segmentation fault/code crash
c) Depends on the compiler
d) xyz
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
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("%s\n", ptrary[1]->name);
return 0;
}
a) Compile time error
b) Depends on the compiler
c) Undefined behaviour
d) xyz
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.
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Apply for C Internship
- Check C Books
- Check Computer Science Books