50 Structure Questions in C

A structure is a user-defined composite data type in the C programming language that enables you to group variables of various data types under a single name. You can create more complex data structures that can represent real-world entities or data with multiple attributes by utilizing structures.

A structure is composed of its constituents, which are variables of varying data types. These members are defined within the structure and are accessible using the name of the structure. Each member of a structure can have its own name and data type, and they can be any valid C data type, such as integers, decimals, characters, arrays, or even other structures.

Explore Free Engineering Handwritten Notes!

Looking for comprehensive study materials on Python, Data Structures and Algorithms (DSA), Object-Oriented Programming (OOPs), Java, Software Testing, and more?

We earn a commission if you make a purchase, at no additional cost to you.

Programming structures are especially useful for organizing and managing related data. They enable the creation of custom data types that encapsulate multiple pieces of information into a single entity, thereby making code more organized, legible, and maintainable.

Structure Questions in C


1. What is a structure in C?

   A) A data type that represents a single value

   B) A data type that represents a collection of values

   C) A mathematical equation

   D) A loop construct

Answer: B) A data type that represents a collection of values


2. Which keyword is used to declare a structure in C?

   A) struct

   B) class

   C) define

   D) typedef

Answer: A) struct


3. Which of the following statements is true about C structures?

   A) They cannot contain other structures.

   B) They can only hold integer values.

   C) They can have members of different data types.

   D) They are not allowed in C.

Answer: C) They can have members of different data types.


4. What is a member of a structure?

   A) A variable that holds an integer value

   B) An operator used to access structure elements

   C) A data item within a structure

   D) A function defined inside a structure

Answer: C) A data item within a structure


5. How do you access the members of a structure in C?

   A) Using the dot (.) operator

   B) Using the arrow (->) operator

   C) Using the square bracket ([]) operator

   D) Using the colon (:) operator

Answer: A) Using the dot (.) operator


6. What is the size of an empty structure in C?

   A) 0 bytes

   B) 1 byte

   C) 4 bytes

   D) It depends on the compiler

Answer: A) 0 bytes


7. How do you define a structure variable in C?

   A) struct myStruct;

   B) myStruct var;

   C) var = struct myStruct;

   D) struct myStruct var;

Answer: D) struct myStruct var;


8. Which operator is used to assign values to structure members?

   A) =

   B) ::

   C) ->

   D) ::

Answer: A) =


9. What is the keyword used to define a structure pointer in C?

   A) structptr

   B) pointerto

   C) struct *

   D) pointer

Answer: C) struct *


10. What is the purpose of using typedef with structures in C?

    A) It defines a new data type based on the structure.

    B) It renames the structure.

    C) It hides the structure members.

    D) It is not allowed with structures.

Answer: A) It defines a new data type based on the structure.


11. Which of the following is true about nesting structures in C?

    A) Structures cannot be nested in C.

    B) Structures can be nested, but only one level deep.

    C) Structures can be nested to multiple levels.

    D) Nesting structures are a compile-time error.

Answer: C) Structures can be nested to multiple levels.


12. What is the keyword used to access a structure member through a pointer in C?

    A) ::

    B) .

    C) ->

    D) ::

Answer: C) ->


13. What is the purpose of the size of the operator in C?

    A) To determine the size of a structure

    B) To calculate the sum of two integers

    C) To find the square root of a number

    D) To compare two strings

Answer: A) To determine the size of a structure


14. How can you compare two structures for equality in C?

    A) Use the == operator

    B) Use a loop to compare each member

    C) Use the memcmp function

    D) Structures cannot be compared for equality

Answer: B) Use a loop to compare each member


15. What is the default access specifier for structure members in C?

    A) public

    B) private

    C) protected

    D) There is no default access specifier

Answer: A) public


16. In C, how can you initialize a structure at the time of declaration?

    A) Using the new keyword

    B) Using the constructor function

    C) By assigning values to its members within curly braces {}

    D) Initialization is not allowed for structures

Answer: C) By assigning values to its members within curly braces {}


17. Which of the following statements is true regarding the scope of structure members in C?

    A) Structure members have a global scope.

    B) Structure members have a local scope.

    C) Structure members have scope within the structure.

    D) Structure members do not have a scope.

Answer: C) Structure members have scope within the structure.


18. What happens if you attempt to access a structure member that does not exist?

    A) It results in a runtime error.

    B) It returns a null value.

    C) It is a compile-time error.

    D) It returns a random value.

Answer: C) It is a compile-time error.


19. Which of the following is used to define an array of structures in C?

    A) struct array[];

    B) struct[] array;

    C) struct array[];

    D) struct array[10];

Answer: D) struct array[10];


20. How do you pass a structure to a function in C?

    A) By Value

    B) By reference

    C) By creating a global structure

    D) Structures cannot be passed to functions

Answer: B) By reference


21. What is the purpose of the offset of macro in C?

    A) To calculate the size of a structure

    B) To find the offset of a member within a structure

    C) To compare two structures

    D) To declare a structure variable

Answer: B) To find the offset of a member within a structure


22. Which library should be included to use the offset of macro in C?

    A) stdlib.h

    B) math.h

    C) stddef.h

    D) assert.h

Answer:  C) stddef.h


23. What is the maximum number of members that a structure can have in C?

    A) 50

    B) 100

    C) There is no maximum limit

    D) 255

Answer:  C) There is no maximum limit


24. Which function is used to allocate memory for a structure dynamically in C?

    A) malloc

    B) calloc

    C) allocate

    D) structure_alloc

Answer:  A) malloc


25. How do you deallocate memory allocated to a structure pointer in C?

    A) Using the free function

    B) Automatically by C’s garbage collector

    C) It is not necessary to deallocate structure memory

    D) Using the delete keyword

Answer:  A) Using the free function


26. What is the purpose of the union in C?

    A) To group multiple structures together

    B) To create a new data type

    C) To represent a single value from a set of possible values

    D) To perform mathematical calculations

Answer:  C) To represent a single value from a set of possible values


27. What is the key difference between a structure and a union in C?

    A) A structure can have members of different data types, while a union cannot.

    B) A structure can only hold single values, while a union can hold multiple values.

    C) A structure is larger in size than a union.

    D) There is no difference between a structure and a union.

Answer:  A) A structure can have members of different data types, while a union cannot.


28. How is memory allocated for a union in C?

    A) Memory is allocated to the largest member.

    B) Memory is allocated for all members separately.

    C) Memory is not allocated for a union.

    D) Memory is allocated to the smallest member.

Answer:  A) Memory is allocated to the largest member.


29. What is the purpose of the enum data type in C?

    A) To declare floating-point numbers

    B) To create custom integer data types

    C) To define character strings

    D) To represent a set of named integer constants

Answer:  D) To represent a set of named integer constants


30. How are enum constants represented in memory?

    A) As character strings

    B) As floating-point numbers

    C) As integer values

    D) Enums cannot be stored in memory

Answer:  C) As integer values


31. In C, can you have a structure member of the same structure type?

    A) Yes

    B) No

    C) Only if it’s the first member

    D) Only if it’s the last member

Answer:  A) Yes


32. What is the purpose of the keyword “volatile” when used with a structure member in C?

    A) It makes the member constant.

    B) It indicates that the member can change without any action being taken by the code.

    C) It prevents the member from being accessed.

    D) It is not a valid use of the “volatile” keyword.

Answer:  B) It indicates that the member can change without any action being taken by the code.


33. What is the primary use of the “bit-field” in a structure in C?

    A) To represent floating-point numbers

    B) To define a member that can hold a single bit

    C) To create an array of integers

    D) To define character strings

Answer:  B) To define a member that can hold a single bit


34. How do you declare a bit-field member in a structure?

    A) int bit_field : 4;

    B) bit_field(4) int;

    C) int bit_field(4);

    D) bit_field int : 4;

Answer:  A) int bit_field : 4;


35. What is the maximum number of bits that can be used in a bit-field member?

    A) 8 bits

    B) 16 bits

    C) 32 bits

    D) It depends on the compiler

Answer:  D) It depends on the compiler


36. What is the purpose of the “pragma pack” directive in C?

    A) To specify the packing alignment for structure members

    B) To declare a new structure

    C) To allocate memory for a structure

    D) To control loop iterations

Answer:  A) To specify the packing alignment for structure members


37. Which of the following operators is used to find the size of a structure without padding?

    A) sizeof

    B) size

    C) size_t

    D) sizeofp

Answer:  A) sizeof


38. What is the significance of padding in a structure in C?

    A) It ensures that structures have a minimum size.

    B) It is used to align structure members to improve memory access speed.

    C) Padding is not used in structures.

    D) It is used to prevent access to structure members.

Answer:  B) It is used to align structure members to improve memory access speed.


39. How can you specify the packing alignment for structure members using “pragma pack”?

    A) #pragma pack(1)

    B) #pragma align(4)

    C) #pragma structure(2)

    D) #pragma padding(8)

Answer:  A) #pragma pack(1)


40. What is the purpose of the “offsetof” macro in C?

    A) To calculate the size of a structure

    B) To calculate the offset of a structure member

    C) To access a structure member

    D) To define a new structure

Answer:  B) To calculate the offset of a structure member


41. In C, can you have a structure member of the same name as the structure itself?

    A) Yes

    B) No

    C) Only if it’s declared inside a function

    D) Only if it’s declared as a bit-field

Answer:  B) No


42. What is the keyword used to define a constant structure in C?

    A) read-only

    B) constant

    C) const

    D) struct const

Answer:  C) const


43. Which keyword is used to access a structure member using a pointer to a structure in C?

    A) ::

    B) .

    C) ->

    D) ::

Answer:  C) ->


44. Which of the following is not a valid way to initialize a structure variable in C?

    A) Using a constructor function

    B) Using a member-wise initialization

    C) Using a default constructor

    D) Using an initializer list

Answer:  C) Using a default constructor


45. What is the difference between “struct” and “typedef struct” in C?

    A) There is no difference; they are the same.

    B) “typedef struct” defines a new data type based on the structure.

    C) “struct” is used to declare a structure, while “typedef struct” is used to declare a structure variable.

    D) “typedef struct” is not a valid syntax in C.

Answer:  B) “typedef struct” defines a new data type based on the structure.


46. Which header file should be included to use the “memcpy” function in C?

    A) stdio.h

    B) string.h

    C) memory.h

    D) memcpy.h

Answer:  B) string.h


47. What is the purpose of the “memcpy” function in C?

    A) To calculate the size of a structure

    B) To copy data from one memory location to another

    C) To compare two structures

    D) To allocate memory for a structure

Answer:  B) To copy data from one memory location to another


48. How do you define a structure that contains a flexible array member in C?

    A) struct flexArray { int data[]; };

    B) struct { int data[]; } flexArray;

    C) struct flexArray { int data[0]; };

    D) struct flexArray { int data[1]; };

Answer:  C) struct flexArray { int data[0]; };


49. In C, can a structure have functions as its members?

    A) Yes

    B) No

    C) Only if the functions are declared outside the structure

    D) Only if the functions are declared as static

Answer:  B) No


50. Which keyword is used to define an anonymous structure in C?

    A) struct

    B) typedef

    C) anonymous

    D) There is no keyword for anonymous structures

Answer:  D) There is no keyword for anonymous structures


Leave a Reply