Search Tutorials


C Structures MCQ Questions and Answers | JavaInUse

C Structures MCQ Questions and Answers

Q. What is a structure in C?

A user-defined data type that allows grouping of related data items.
A built-in data type used to store data in memory.
A method to organize and manage data in an array.
A way to create functions that operate on specific data types.

Q. How do you declare a structure in C?

Using the struct keyword followed by the structure name and curly braces.
Using the keyword data followed by the structure name and curly braces.
Using the #define directive followed by the structure name and curly braces.
Using the typedef keyword followed by the structure name and curly braces.

Q. How do you create a variable of a structure type?

By using the struct keyword followed by the structure name.
By using the new keyword followed by the structure name.
By using the malloc() function to allocate memory for the structure.
By using the & operator to access the structure's memory address.

Q. How do you access members of a structure?

Using the . (dot) operator followed by the member name.
Using the -> (arrow) operator followed by the member name.
Using the [] (bracket) operator followed by the member index.
Using the : (colon) operator followed by the member name.

Q. Can a structure contain another structure as a member?

Yes, a structure can contain another structure as a member.
No, structures cannot contain other structures.
It depends on the compiler and the platform.
It is possible, but only if the inner structure is declared first.

Q. What is a structure pointer?

A pointer that points to a structure variable.
A special type of pointer used only with structures.
A pointer that stores the address of a structure in memory.
A way to access and manipulate structures dynamically.

Q. How do you pass a structure to a function?

By value, using the struct keyword followed by the structure name.
By reference, using the & operator followed by the structure variable name.
By value, using the * operator followed by the structure variable name.
By reference, using the address-of & operator followed by the structure variable name.

Q. Can you return a structure from a function?

Yes, you can return a structure from a function.
No, you cannot return structures from functions.
You can return a structure by value, but not by reference.
You can return a pointer to a structure, but not the structure itself.





Q. Can you compare two structures for equality?

Yes, you can compare two structures for equality using the == operator.
No, you cannot directly compare structures for equality.
You can compare structures for equality using the strcmp() function.
You can compare structures for equality only if they have the same memory address.

Q. How do you copy one structure to another?

By using the = operator to assign one structure to another.
By using the memcpy() function to copy the memory contents.
By using a loop to copy each member of the structure individually.
By using the address-of & operator to point one structure to another.

Q. Can a structure be an element of an array?

Yes, a structure can be an element of an array.
No, structures cannot be elements of arrays.
It depends on the size of the structure and the array.
Structures can be elements of arrays, but only if the array is dynamically allocated.

Q. How do you access a specific structure in an array of structures?

By using the [] (bracket) operator followed by the index of the structure.
By using a pointer and the * operator to access the desired structure.
By using the address-of & operator followed by the index of the structure.
By using a loop to iterate through the array and access each structure.

Q. Can a structure contain an array as a member?

Yes, a structure can contain an array as a member.
No, structures cannot contain arrays as members.
It depends on the size of the array and the structure.
Structures can contain arrays as members, but only if the array is dynamically allocated.

Q. What is a structure in C?

A. A structure is a user-defined data type that allows grouping related data items of different types under a single name.
B. A structure is a built-in data type used to store integer values.
C. A structure is a data type used to organize and manipulate data in memory.
D. None of the above.

Q. How do you declare a structure in C?

A. Use the struct keyword followed by the structure name and curly braces to define the structure members.
B. Use the #struct directive to declare a structure.
C. Declare a structure using the keyword struct, followed by a semicolon.
D. Structures cannot be declared in C.

Q. How do you define a variable of a structure type?

A. Use the struct keyword followed by the structure name and then the variable name.
B. Use the #define directive to define a structure variable.
C. Declare a variable with the same name as the structure.
D. Use the struct keyword followed by the variable name and then the structure name.

Q. How do you access members of a structure?

A. Use the dot (.) operator to access members of a structure.
B. Use the arrow (->) operator to access members of a structure.
C. Both A and B are correct.
D. Neither A nor B are correct.

Q. Can you declare an array of structures? How?

A. Yes, you can declare an array of structures by specifying the array size inside square brackets after the structure name.
B. No, arrays of structures are not allowed in C.
C. You can declare an array of structures using the #array directive.
D. You need to use a separate keyword, struct_array, to declare an array of structures.

Q. What is a self-referential structure?

A. A self-referential structure is a structure that contains a pointer to another structure of the same type.
B. A self-referential structure is a structure that contains a pointer to itself.
C. A self-referential structure is a structure that is defined inside another structure.
D. A self-referential structure is a structure that contains a function pointer to a function that operates on the same structure type.

Q. How do you pass a structure to a function?

A. Pass the structure variable as an argument to the function.
B. Use the address-of (&) operator to pass a pointer to the structure to the function.
C. Structures cannot be passed to functions in C.
D. Use the dot (.) operator to pass a structure to a function.

Q. Can you return a structure from a function?

A. Yes, you can return a structure from a function by value.
B. No, you cannot return structures from functions in C.
C. You can return a structure from a function by passing a pointer to the structure.
D. You need to use a special keyword, return_struct, to return a structure.

Q. What is a nested structure?

A. A nested structure is a structure that is defined inside another structure.
B. A nested structure is a structure that contains another structure as one of its members.
C. A nested structure is a structure that is defined inside a function.
D. A nested structure is a structure that contains an array of structures as one of its members.

Q. How do you initialize a structure variable?

A. Use the assignment operator (=) to assign values to each member of the structure.
B. Use the struct keyword followed by the structure name and curly braces to initialize the members.
C. You cannot initialize a structure variable in C.
D. Use the #init directive to initialize a structure variable.

Q. Can you compare two structures for equality in C?

A. Yes, you can use the == operator to compare two structures for equality.
B. No, you cannot directly compare two structures for equality in C.
C. You can use the < and > operators to compare structures.
D. You need to define a custom function to compare structures for equality.