C Programming Questions and Answers on Basics of Structures for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_24.html
1. Which of the following are themselves a collection of different data types?
a) string
b) structures
c) char
d) all of the mentioned
Answer: b
2. User-defined data type can be derived by___________
a) struct
b) enum
c) typedef
d) all of the mentioned
Answer: d
3. Which operator connects the structure name to its member name?
a) –
b) <- br="">c) .
d) Both <- .="" and="" br="">
Answer: c
4. Which of the following cannot be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
Answer: b
5. Which of the following structure declaration will throw an error?
a) struct temp{}s;
main(){}
b) struct temp{};
struct temp s;
main(){}
c) struct temp s;
struct temp{};
main(){}
d) None of the mentioned
Answer: d
6. What is the output of this C code?
#include
struct student
{
int no;
char name[20];
}
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
a) Compile time error
b) Nothing
c) hello
d) Varies
b) Nothing
c) hello
d) Varies
Answer: a
7. What is the output of this C code?
#include
struct student
{
int no = 5;
char name[20];
};
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
a) Nothing
b) Compile time error
c) hello
d) Varies
b) Compile time error
c) hello
d) Varies
Answer: b
8. What is the output of this C code?
#include
struct student
{
int no;
char name[20];
};
void main()
{
student s;
s.no = 8;
printf("hello");
}
a) Nothing
b) hello
c) Compile time error
d) Varies
b) hello
c) Compile time error
d) Varies
Answer: c
9. What is the output of this C code?
#include
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%d", s.no);
}
a) Nothing
b) Compile time error
c) Junk
d) 8
b) Compile time error
c) Junk
d) 8
Answer: d
10. Can the above code be compiled successfully?
#include
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .f = 3, .k = 1};
printf("%f\n", x.f);
}
a) Yes
b) No
c) Depends on the standard
d) Depends on the platform
b) No
c) Depends on the standard
d) Depends on the platform
Answer: c
11. What is the output of this 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
b) Compile time error
c) Junk
d) 8
Answer: b
12. Number of bytes in memory taken by the below structure is
#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
View AnswerAnswer: a
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
View AnswerAnswer: a
13. What is the output of this C code?
#include
struct
{
int k;
char c;
};
int main()
{
struct p;
p.k = 10;
printf("%d\n", p.k);
}
a) Compile time error
b) 10
c) Undefined behaviour
d) Segmentation fault
b) 10
c) Undefined behaviour
d) Segmentation fault
Answer: a
.
.
14. What is the output of this C code?
#include
struct
{
int k;
char c;
} p;
int p = 10;
int main()
{
p.k = 10;
printf("%d %d\n", p.k, p);
}
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: a
15. What is the output of this C code?
#include
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: b
16. What is the output of this C code?
#include
struct p
{
int k;
char c;
float f;
};
int p = 10;
int main()
{
struct p x = {1, 97};
printf("%f %d\n", x.f, p);
}
a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
Answer: b
17. What is the output of this 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("%f\n", x.f);
}
a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
Answer: a
18. What is the output of this 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
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
19. What is the output of this C code(according to C99 standard)?
#include
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97};
printf("%f\n", x.f);
}
a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
Answer: a