Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 91–100 of 291
Topics in C Programming
Which of the following statements about structures is TRUE?
A A structure is a collection of variables of the same data type
B A structure is a collection of variables of different data types grouped under a single name
C A structure cannot contain pointers
D A structure occupies memory equal to the sum of its members without any padding
Correct Answer:  B. A structure is a collection of variables of different data types grouped under a single name
EXPLANATION

A structure allows grouping of different data types. Padding may be added by the compiler for alignment.

Test
Which of the following is the correct way to initialize a structure in C?
A struct Point p = {10, 20};
B struct Point p; p = {10, 20};
C Point p = {10, 20};
D p.x = 10; p.y = 20; (without declaration)
Correct Answer:  A. struct Point p = {10, 20};
EXPLANATION

Structures must be initialized at declaration time using curly braces. Assignment of initializer list is not valid after declaration.

Test
Which of the following correctly demonstrates a typedef for a structure?
A typedef struct { int x; int y; } Point;
B struct typedef Point { int x; int y; };
C define struct Point { int x; int y; };
D struct Point typedef { int x; int y; };
Correct Answer:  A. typedef struct { int x; int y; } Point;
EXPLANATION

The correct syntax for typedef struct is: typedef struct { members } StructName;

Test
How do you access a member of a structure through a pointer in C?
A Using dot operator (.)
B Using arrow operator (->)
C Using asterisk (*)
D Using ampersand (&)
Correct Answer:  B. Using arrow operator (->)
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. The dot operator is used with direct variables.

Test
Consider: union Data { int i; float f; char c; }; What is the size of this union?
A 4 bytes
B 9 bytes
C 5 bytes
D 12 bytes
Correct Answer:  A. 4 bytes
EXPLANATION

The size of a union equals the size of its largest member. Here, int is 4 bytes (largest), so union size is 4 bytes.

Test
Which of the following statements about unions is correct?
A Union members share the same memory location
B Union size equals the sum of all member sizes
C All union members can hold values simultaneously
D Union requires more memory than structure
Correct Answer:  A. Union members share the same memory location
EXPLANATION

Union members share the same memory location, and the union size equals the size of its largest member.

Test
What is the correct way to dynamically allocate an array of structures?
struct Student { int roll; char name[50]; };
A struct Student *arr = (struct Student*)malloc(n * sizeof(struct Student));
B struct Student arr = (struct Student*)malloc(n * sizeof(char));
C struct Student *arr = malloc(n);
D Student *arr = malloc(n * Student);
Correct Answer:  A. struct Student *arr = (struct Student*)malloc(n * sizeof(struct Student));
EXPLANATION

Correct allocation requires pointer declaration, proper cast, and multiplying n with sizeof(struct Student).

Test
When structure is passed by value to a function, which of these is true?
A Changes to structure members inside function affect the original
B The entire structure is copied onto the stack
C Only pointers within the structure are copied
D Memory is shared between function and caller
Correct Answer:  B. The entire structure is copied onto the stack
EXPLANATION

Pass by value creates a complete copy of the structure on the function's stack frame.

Test
Which of the following correctly demonstrates self-referential structure (for linked list)?
A struct Node { int data; struct Node *next; };
B struct Node { int data; Node *next; };
C struct Node { int data; *next; };
D Node { int data; Node *next; };
Correct Answer:  A. struct Node { int data; struct Node *next; };
EXPLANATION

In C, self-referential structures require the struct keyword in pointer declarations within the structure definition.

Test
Which of these is a valid declaration of a structure variable using dot operator immediately after struct definition?
A struct Point { int x; int y; } p;
B struct Point { int x; int y; }; Point p;
C struct { int x; int y; } p;
D Both A and C
Correct Answer:  D. Both A and C
EXPLANATION

Both methods are valid - A uses named struct tag with variable declaration, C uses anonymous struct with variable declaration.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips