Here is a listing of C multiple choice questions on “Basics of Structures” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
struct student
-
{
-
int no;
-
char name[20];
-
};
-
struct student s;
-
no = 8;
-
printf("%d", no);
-
}
a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: b
Clarification: None.
2. How many bytes in memory taken by the following C structure?
-
#include
-
struct test
-
{
-
int k;
-
char c;
-
};
a) Multiple of integer size
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
Answer: a
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
struct
-
{
-
int k;
-
char c;
-
};
-
int main()
-
{
-
struct p;
-
p.k = 10;
-
printf("%dn", p.k);
-
}
a) Compile time error
b) 10
c) Undefined behaviour
d) Segmentation fault
Answer: a
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
struct
-
{
-
int k;
-
char c;
-
} p;
-
int p = 10;
-
int main()
-
{
-
p.k = 10;
-
printf("%d %dn", p.k, p);
-
}
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
struct p
-
{
-
int k;
-
char c;
-
};
-
int p = 10;
-
int main()
-
{
-
struct p x;
-
x.k = 10;
-
printf("%d %dn", x.k, p);
-
}
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
struct p
-
{
-
int k;
-
char c;
-
float f;
-
};
-
int p = 10;
-
int main()
-
{
-
struct p x = {1, 97};
-
printf("%f %dn", x.f, p);
-
}
a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
Answer: b
Clarification: None.
7. What will be the output of the following C code according to C99 standard?
-
#include
-
struct p
-
{
-
int k;
-
char c;
-
float f;
-
};
-
int main()
-
{
-
struct p x = {.c = 97, .f = 3, .k = 1};
-
printf("%fn", x.f);
-
}
a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
Answer: a
Clarification: None.
8. What will be the output of the following C code according to C99 standard?
-
#include
-
struct p
-
{
-
int k;
-
char c;
-
float f;
-
};
-
int main()
-
{
-
struct p x = {.c = 97, .k = 1, 3};
-
printf("%f n", x.f);
-
}
a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
Clarification: None.
9. What will be the output of the following C code according to C99 standard?
-
#include
-
struct p
-
{
-
int k;
-
char c;
-
float f;
-
};
-
int main()
-
{
-
struct p x = {.c = 97};
-
printf("%fn", x.f);
-
}
a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
Answer: a
Clarification: None.