wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on Structures in C

Total questions: 99

Worksheet time: 50mins

Name
Class
Date
1.

Which keyword is used to define a structure in C?

a)

struct

b)

class

c)

typedef

d)

enum

2.

What does a structure in C allow you to do?

a)

Group related variables of different data types under a single name

b)

Store only integer values

c)

Create only arrays

d)

Allocate memory for functions

3.

What is the role of StructureName in a structure definition in C?

a)

It is the identifier of the structure

b)

It is a keyword in C

c)

It is a function name

d)

It is a variable name

4.

When is memory allocated for a structure in C?

a)

When a variable of that structure is created

b)

When the structure is defined

c)

When the program starts

d)

When the compiler is installed

5.

Given the following structure definition, how would you declare two variables of this structure in C?

a)

struct Student student1, student2;

b)

Student student1, student2;

c)

struct student1, student2;

d)

int student1, student2;

6.

Which of the following is a correct way to declare structure variables at the end of a structure definition in C?

a)

struct Student { int roll_number; char name[20]; float percentage; } s1, s2;

b)

struct Student { int roll_number; char name[20]; float percentage; };

c)

struct Student s1, s2 { int roll_number; char name[20]; float percentage; };

d)

struct Student { int roll_number; char name[20]; float percentage; } = s1, s2;

7.

Why is it preferred to declare structure variables separately when multiple variables are required?

a)

It allows structure variables to be declared outside the structure definition.

b)

It makes the code run faster.

c)

It reduces the memory usage of the program.

d)

It prevents syntax errors in C.

8.

Given the following structure definition, which of the following correctly declares two structure variables separately? struct Student { int roll_number; char name[20]; float percentage; };

a)

struct Student s1, s2;

b)

Student s1, s2;

c)

struct s1, s2;

d)

struct Student { s1, s2; };

9.

What data types are used for the members of the 'Student' structure in the provided example?

a)

int, char array, float

b)

float, int, double

c)

char, int, float

d)

int, char, double

10.

Suppose you want to declare three variables of a structure named 'Employee' with members 'id' (int), 'name' (char[30]), and 'salary' (float). Which is the correct way to declare them separately?

a)

struct Employee emp1, emp2, emp3;

b)

Employee emp1, emp2, emp3;

c)

struct Employee { emp1, emp2, emp3; };

d)

struct emp1, emp2, emp3;

11.

Which of the following is TRUE about initializing structure members inside the structure definition in C?

a)

A) Structure members can be initialized inside the structure definition without any error.

b)

B) Structure members cannot be initialized inside the structure definition; it causes a compiler error.

c)

C) Structure members can only be initialized if they are integers.

d)

D) Structure members can be initialized only if the structure is global.

12.

What is the correct way to initialize the members of a structure in C?

a)

A) By assigning values directly inside the structure definition.

b)

B) By creating a structure variable and then assigning values to its members.

c)

C) By using the 'init' keyword inside the structure.

d)

D) By declaring the structure as static.

13.

Given the following structure definition, which line of code correctly initializes the roll_number member? struct student { int roll_number; char name[20]; float percentage; };

a)

A) int roll_number = 10;

b)

B) student.roll_number = 10;

c)

C) s1.roll_number = 10;

d)

D) roll_number := 10;

14.

Why is memory not allocated to a structure’s data members when the structure is defined?

a)

A) Because the structure is not a variable.

b)

B) Because memory is only allocated when a structure variable is declared.

c)

C) Because the compiler ignores structure definitions.

d)

D) Because only global variables are allocated memory.

15.

Suppose you try to initialize a structure member inside the structure definition. What will happen?

a)

A) The program will run successfully.

b)

B) The compiler will throw an error.

c)

C) The member will be initialized to zero.

d)

D) The member will be initialized to a random value.

16.

Consider the following code snippet: struct student { int roll_number=10; float percentage=66.7; }; What is the result of compiling this code?

a)

A) The code compiles and runs successfully.

b)

B) The code compiles but does not run.

c)

C) The code throws a compilation error.

d)

D) The code initializes the members to zero.

17.

How can you modify the values of a structure’s members after declaring a structure variable?

a)

A) By accessing the members using the structure variable and assigning new values.

b)

B) By redefining the structure.

c)

C) By using the 'update' keyword.

d)

D) By declaring the members as global variables.

18.

Which operator is used to access members of a structure variable in C?

a)

Dot operator (.)

b)

Comma operator (,)

c)

Semicolon operator (;)

d)

Colon operator (:)

19.

What is the correct way to initialize a structure variable using normal assignment in C?

a)

s1.roll_number = 101; strcpy(s1.name, "Kumar"); s1.percentage = 74.6;

b)

s1 = {101, "Kumar", 74.6};

c)

s1->roll_number = 101; strcpy(s1->name, "Kumar"); s1->percentage = 74.6;

d)

s1.roll_number == 101; strcpy(s1.name, "Kumar"); s1.percentage == 74.6;

20.

Which of the following is an example of initializing a structure variable at the time of declaration in C?

a)

struct student s1 = {101, "Kumar", 74.5};

b)

s1.roll_number = 101;

c)

strcpy(s1.name, "Kumar");

d)

s1.percentage = 74.6;

21.

Explain the difference between normal assignment and initialization at the time of declaration for structure variables in C. (DoK Level 2)

a)

Normal assignment sets values after declaration, while initialization assigns values during declaration.

b)

Both methods assign values during declaration.

c)

Normal assignment is only used for arrays.

d)

Initialization at the time of declaration cannot be used for structures.

22.

Given the structure definition below, which statement correctly assigns the value "Kumar" to the name member of the structure variable s1? (DoK Level 2) struct Student { int roll_number; char name[20]; float percentage; };

a)

strcpy(s1.name, "Kumar");

b)

s1.name = "Kumar";

c)

s1->name = "Kumar";

d)

s1.name == "Kumar";

23.

A student wants to create a structure variable and initialize all its members at once. Which method should they use? (DoK Level 3)

a)

Initialization at the time of declaration

b)

Normal assignment after declaration

c)

Using only the dot operator

d)

Using only the arrow operator

24.

Which syntax is used to access a member of a structure by its variable in C?

a)

structVariable -> structMember;

b)

structVariable . structMember;

c)

structVariable : structMember;

d)

structVariable * structMember;

25.

How are structure members stored in memory in C?

a)

Random memory locations

b)

Contiguous (adjacent) memory locations

c)

Non-contiguous memory locations

d)

Only in registers

26.

In the given structure example, how many bytes does the 'name' member occupy?

a)

4 bytes

b)

8 bytes

c)

16 bytes

d)

1 byte

27.

What is the total memory occupied by the structure 'student' in the example provided?

a)

8 bytes

b)

12 bytes

c)

16 bytes

d)

20 bytes

28.

Why are nested structures used in C programming?

a)

To increase the speed of execution

b)

To allow the creation of more complex and organized data structures

c)

To reduce memory usage

d)

To avoid using arrays

29.

Given a structure with an int, a char array of size 8, and a float, explain how the memory is allocated for each member and calculate the total memory used.

a)

int: 2 bytes, char array: 8 bytes, float: 2 bytes, total: 12 bytes

b)

int: 4 bytes, char array: 8 bytes, float: 4 bytes, total: 16 bytes

c)

int: 4 bytes, char array: 4 bytes, float: 4 bytes, total: 12 bytes

d)

int: 8 bytes, char array: 8 bytes, float: 8 bytes, total: 24 bytes

30.

Which of the following is NOT a benefit of using nested structures in C?

a)

A) Logical grouping of related data

b)

B) Improves code readability and maintainability

c)

C) Data re-usability

d)

D) Increases code execution speed

31.

What are the two primary types of nested structures in C?

a)

A) Direct and Indirect Structure

b)

B) Embedded and Separate Structure

c)

C) Inline and Outline Structure

d)

D) Static and Dynamic Structure

32.

In the context of embedded structures in C, what does direct nesting (named nesting) refer to?

a)

A) Defining the inner structure outside the outer structure

b)

B) Defining the inner structure directly inside the outer structure and giving it a name

c)

C) Using pointers to link two structures

d)

D) Declaring structures without any members

33.

Which statement about inner structure access in direct nesting is correct?

a)

A) Inner structure cannot be accessed via the outer structure

b)

B) Inner structure can only be accessed anonymously

c)

C) Inner structure can be accessed via the outer structure

d)

D) Inner structure must be defined outside the outer structure

34.

Given the syntax for direct nesting in C, what is the purpose of 'inner_stru_var_name'?

a)

A) It is the name of the outer structure

b)

B) It is a variable of the inner structure

c)

C) It is a function to access data members

d)

D) It is a pointer to the outer structure

35.

Why might a programmer choose to use embedded structures in their code?

a)

A) To increase the number of global variables

b)

B) To enhance code organization and readability

c)

C) To reduce the number of functions

d)

D) To avoid using data members

36.

Which header file is included at the beginning of the provided C source code for structured programming?

a)

b)

c)

d)

37.

In the given C code, what is the name of the structure that is directly nested inside the 'Student' structure?

a)

Address

b)

Location

c)

City

d)

Place

38.

What is the purpose of the 'scanf("%d", &s.roll);' statement in the provided code?

a)

To read the roll number from user input

b)

To print the roll number

c)

To assign a default value to roll number

d)

To read the name from user input

39.

Which of the following correctly describes the type of nesting used in the 'Student' structure in the provided code?

a)

Direct named nesting

b)

Anonymous nesting

c)

Indirect nesting

d)

Pointer-based nesting

40.

Suppose you want to add a new field 'state' to the address structure in the provided code. Where should you add it?

a)

Inside the struct Address, before the closing curly brace

b)

Outside the struct Student

c)

After the return statement in main()

d)

Before the #include statement

41.

If a student enters the following details: Roll Number = 101, Name = "John", City = "Hyderabad", Pincode = 500001, what will be printed for the city in the output?

a)

Hyderabad

b)

John

c)

101

d)

500001

42.

Which of the following best describes an anonymous nested structure in C?

a)

A structure defined inside another structure without a specific name for the inner structure.

b)

A structure defined outside any other structure with a specific name.

c)

A structure that only contains integer data members.

d)

A structure that cannot be accessed from the outer structure.

43.

In the provided example, what are the members of the anonymous inner structure within the Student structure?

a)

roll and name

b)

city and pincode

c)

addr and roll

d)

name and addr

44.

What is the purpose of using an anonymous nested structure in C programming?

a)

To allow direct access to inner structure members through the outer structure's instance.

b)

To prevent access to inner structure members.

c)

To make the code more complex and harder to read.

d)

To avoid using any data members in the structure.

45.

Given the following code snippet, what is the correct way to access the city member of the anonymous inner structure? struct Student { int roll; char name[50]; struct { char city[30]; int pincode; } addr; };

a)

s.city

b)

s.addr.city

c)

s.name.city

d)

s.roll.city

46.

Suppose you want to add a new member 'state' to the anonymous inner structure in the Student structure. Which of the following is the correct way to declare it?

a)

struct { char city[30]; int pincode; char state[20]; } addr;

b)

struct { char state[20]; } addr;

c)

struct Student { char state[20]; };

d)

struct { int roll; char state[20]; } addr;

47.

Which of the following best describes a "separate structure" approach in nested structures in C programming?

a)

A) The inner structure is defined directly inside the outer structure.

b)

B) The inner structure is defined independently and included as a member in the outer structure.

c)

C) The outer structure is defined inside the inner structure.

d)

D) Both structures are defined together in a single block.

48.

In the syntax for separate structures, how is the inner structure included in the outer structure?

a)

A) By declaring it as a pointer.

b)

B) By defining it inside the outer structure.

c)

C) By including it as a member of the outer structure.

d)

D) By using a typedef.

49.

What is the main difference between "separate structure" and "embedded structure" in C programming?

a)

A) Separate structure uses pointers, embedded structure does not.

b)

B) Separate structure defines the inner structure independently, embedded structure defines it inside the outer structure.

c)

C) Embedded structure uses arrays, separate structure does not.

d)

D) Embedded structure is used only for functions, separate structure is used for variables.

50.

Given the following code snippet, what is the name of the structure that stores the city and pin information? struct Address { char city[20]; int pin; };

a)

A) Employee

b)

B) Address

c)

C) CityPin

d)

D) Location

51.

If you want to store and display employee details using separate structures in C, which header file must be included?

a)

A)

b)

B)

c)

C)

d)

D)

52.

Why might a programmer choose to use separate structures instead of embedded structures in C?

a)

A) To make the code less readable.

b)

B) To allow reuse of the inner structure in multiple outer structures.

c)

C) To reduce the number of variables.

d)

D) To avoid using functions.

53.

Which of the following is a correct way to declare a structure in C that contains an array and an integer?

a)

struct Student { int roll; char name[20]; int marks[5]; };

b)

struct Student { int roll; int marks[5]; char name[20]; };

c)

struct Student { char name[20]; int roll; int marks[5]; };

d)

struct Student { int marks[5]; char name[20]; int roll; };

54.

What is the purpose of using a structure in C programming?

a)

To store only one type of data

b)

To store multiple elements of different data types in a single variable

c)

To perform mathematical operations

d)

To create loops

55.

In the provided code, which member of the struct Employee is itself a structure?

a)

id

b)

name

c)

addr

d)

pin

56.

Why might you use an array within a structure in C?

a)

To store only one value

b)

To store multiple values of the same type together with other types

c)

To increase the speed of the program

d)

To avoid using functions

57.

Given the following code snippet, what will be printed if the user enters 101 for ID, "John" for name, "NYC" for city, and 12345 for pin?

a)

ID: 101, Name: John, City: NYC, Pin: 12345

b)

ID: John, Name: 101, City: NYC, Pin: 12345

c)

ID: NYC, Name: John, City: 101, Pin: 12345

d)

ID: 12345, Name: John, City: NYC, Pin: 101

58.

Which header file is necessary to use printf and scanf functions in C?

a)

b)

c)

d)

59.

What is the purpose of using an array of structures in C?

a)

To store multiple structure variables together in a single array

b)

To store only integer values

c)

To store only floating-point values

d)

To store only character values

60.

Which of the following is the correct way to declare a structure named 'Student' in C?

a)

struct Student { int id; char name[20]; };

b)

struct Student ( int id; char name[20]; )

c)

Student struct { int id; char name[20]; }

d)

struct Student: int id, char name[20];

61.

In the provided C code, what does the following line do? scanf("%s", s1.name);

a)

Reads a string input and stores it in the 'name' field of structure s1

b)

Prints the name of the student

c)

Reads an integer input and stores it in the 'name' field of structure s1

d)

Initializes the 'name' field of structure s1 to NULL

62.

How many marks does the program ask the user to enter for each student?

a)

5

b)

10

c)

3

d)

1

63.

How would you use an array of structures to store information for multiple students in C?

a)

By declaring multiple integer arrays for each student

b)

By declaring an array of 'Student' structures and storing each student's data in a separate element of the array

c)

By using only global variables

d)

By using a single structure for all students

64.

Which of the following best describes a union in C programming?

a)

A data type that allows storing multiple values of different data types at the same time.

b)

A user-defined data type that allows storing multiple values with different data types in the same memory location, but only one member can contain a value at any given time.

c)

A built-in data type that stores only integer values.

d)

A data type that allows storing only one value at a time.

65.

What is the main advantage of using a union in C?

a)

It allows storing multiple values of the same type.

b)

It provides an efficient way of using the same memory location for multiple purposes.

c)

It increases the memory usage for each variable.

d)

It restricts the number of members to one.

66.

Given the following syntax, what does 'union_variable' represent? union union_name { datatype member-1; datatype member-2; ... datatype member-n; } union_variable;

a)

The name of the union type.

b)

The name of a member inside the union.

c)

The variable of the union type.

d)

The datatype of the union.

67.

In the provided C code, what is the purpose of the for loop?

a)

To declare an array of structures.

b)

To display the details of each student in the array.

c)

To calculate the average marks of students.

d)

To initialize the structure members.

68.

Why can only one member of a union contain a value at any given time?

a)

Because all members share the same memory location.

b)

Because unions are only for integer values.

c)

Because unions do not support multiple members.

d)

Because each member has its own memory location.

69.

How would you declare a union with three members: an integer, a float, and a character in C?

a)

union myUnion { int a; float b; char c; } myVar;

b)

struct myUnion { int a; float b; char c; } myVar;

c)

union myUnion ( int a, float b, char c ) myVar;

d)

union myUnion { int a, float b, char c; } myVar;

70.

If you assign a value to one member of a union, what happens to the values of the other members?

a)

They remain unchanged.

b)

They are overwritten or become undefined.

c)

They are set to zero.

d)

They are copied to the assigned member.

71.

Which keyword is used to define a union in C programming?

a)

union

b)

struct

c)

class

d)

enum

72.

In a union, how is memory allocated for its members?

a)

Memory is allocated for each member separately.

b)

Memory is allocated for the member that requires the highest memory.

c)

Memory is allocated for the smallest member.

d)

Memory is allocated equally for all members.

73.

What is the correct syntax for declaring a variable of union type in C?

a)

union union_name var1, var2, ... varn;

b)

struct union_name var1, var2, ... varn;

c)

class union_name var1, var2, ... varn;

d)

enum union_name var1, var2, ... varn;

74.

Given the union declaration: union Student { int rno; char sname[100], cname[50]; }; What will be the size of the memory location allocated for a variable of this union?

a)

50 bytes

b)

100 bytes

c)

150 bytes

d)

4 bytes

75.

Why does the variable 's' of union Student only allocate one memory location?

a)

Because unions allocate memory for the largest member only.

b)

Because unions allocate memory for all members separately.

c)

Because unions do not require memory allocation.

d)

Because unions allocate memory for the smallest member only.

76.

In the provided C program, what is the purpose of the statement 'scanf("%d",&s.rno);'?

a)

To print the value of rno.

b)

To assign a value to rno from user input.

c)

To declare the variable rno.

d)

To allocate memory for rno.

77.

If you want to access the member 'cname' in the union 'student', which syntax should you use?

a)

student.cname

b)

s.cname

c)

student->cname

d)

s->cname

78.

Explain why only one member of a union can be accessed at a time.

a)

Because all members share the same memory location.

b)

Because each member has its own memory location.

c)

Because unions do not support multiple members.

d)

Because unions are similar to arrays.

79.

Which keyword is used to define a structure in C?

a)

struct

b)

union

c)

class

d)

object

80.

What is the main difference in memory allocation between a structure and a union in C?

a)

Structure members have separate memory, while union members share the same memory.

b)

Structure members share the same memory, while union members have separate memory.

c)

Both structure and union members have separate memory.

d)

Both structure and union members share the same memory.

81.

In a union, how many members can hold a value at a time?

a)

Only one member

b)

All members

c)

Two members

d)

None

82.

Which feature allows all members of a structure to be accessed at the same time?

a)

Independent access

b)

Simultaneous access

c)

Single access

d)

Sequential access

83.

When is it useful to use a structure in C programming?

a)

When storing information about an entity with multiple attributes

b)

When storing a value that may be of different types at different times

c)

When only one value needs to be stored

d)

When memory-saving is not required

84.

What is the correct syntax for declaring a structure variable in C?

a)

Struct StructureName { Datatype member1; Datatype member2; Datatype memberN; }structure_variable;

b)

union StructureName { Datatype member1; Datatype member2; Datatype memberN; }union_variable;

c)

class StructureName { Datatype member1; Datatype member2; Datatype memberN; }class_variable;

d)

object StructureName { Datatype member1; Datatype member2; Datatype memberN; }object_variable;

85.

Why might a union be preferred over a structure in certain situations?

a)

To save memory when storing different types at different times

b)

To store multiple attributes of an entity

c)

To allow all members to be accessed independently

d)

To initialize all members at once

86.

Which member of a union can be initialized at declaration?

a)

Only the first member

b)

All members

c)

Only the last member

d)

None

87.

Given the following code snippet, what will be the output if the student name entered is "Raja" and the cname entered is "CSE"? printf("Enter student name : "); scanf("%s",&s.sname); printf("Sname=%s\n",s.sname); printf("Enter cname : "); scanf("%s",&s.cname); printf("Cname=%s\n",s.cname);

a)

Sname=Raja Cname=CSE

b)

Sname=Raja Cname=Raja

c)

Sname=CSE Cname=Raja

d)

Sname=Raja Cname=Student

88.

Memory allocation differs between structures and unions in C. Which of the following statements best explains this difference and provides a scenario where it is significant?

a)

Structures allocate separate memory for each member, while unions share the same memory among all members. This is significant when memory usage is a concern, such as in embedded systems where unions can save space by storing only one value at a time.

b)

Structures share the same memory for all members, while unions allocate separate memory for each member. This is significant when storing multiple attributes.

c)

Both structures and unions allocate separate memory for each member. This is significant when memory usage is not a concern.

d)

Both structures and unions share the same memory for all members. This is significant when memory usage is not a concern.

89.

Which of the following is a correct use of the typedef keyword in C language?

a)

typedef int number;

b)

typedef number int;

c)

typedef int;

d)

typedef int new;

90.

What is the main purpose of using typedef in C language?

a)

To create a new variable

b)

To create a new name (alias) for an existing data type

c)

To declare a function

d)

To initialize a structure

91.

In the provided example, what does 'vvit' represent after the statement 'typedef int vvit;'?

a)

A new variable

b)

A function

c)

An alias for int

d)

A structure

92.

Which of the following is NOT an advantage of using typedef in C?

a)

Makes code shorter and cleaner

b)

Improves portability

c)

Avoids repeatedly writing long type declarations

d)

Increases the execution speed of the program

93.

Given the following code snippet, what will be the output? typedef int vvit; int main() { vvit a = 10, b = 20; printf("a = %d, b = %d\n", a, b); return 0; }

a)

a = 10, b = 20

b)

a = 20, b = 10

c)

a = 0, b = 0

d)

Compilation error

94.

Why is typedef considered useful with structures and pointers in C?

a)

It allows direct memory access

b)

It makes code more readable and easier to maintain

c)

It increases the size of the data type

d)

It changes the value of variables

95.

Which of the following is the correct syntax for typedef in C?

a)

typedef new_data_type_name existing_data_type;

b)

typedef existing_data_type new_data_type_name;

c)

typedef new_data_type existing_data_type_name;

d)

typedef data_type;

96.

Consider the following struct definition without typedef: struct Student { int id; char name[20]; }; Which of the following is the correct way to declare a variable of this struct?

a)

Student s1;

b)

struct Student s1;

c)

typedef Student s1;

d)

Student struct s1;

97.

Which keyword is used to define a structure in C?

a)

struct

b)

typedef

c)

enum

d)

define

98.

What is the main advantage of using typedef with struct in C?

a)

It allows the struct to act as a new data type.

b)

It increases the speed of the program.

c)

It automatically initializes struct members.

d)

It prevents memory leaks.

99.

What does the enum keyword stand for in C language?

a)

Enumeration

b)

Environment

c)

Encryption

d)

Entity