Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 101–110 of 303
Topics in C Programming
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.

Take 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.

Take Test
Consider union u { int i; char c; float f; }; What is the size of this union?
A 4 bytes
B 9 bytes
C 7 bytes
D Depends on compiler
Correct Answer:  A. 4 bytes
EXPLANATION

Union size equals the largest member size. float is typically 4 bytes, which is largest.

Take Test
Which of the following is true about typedef struct?
A typedef struct creates a named type, eliminating need for 'struct' keyword in declarations
B typedef struct is less efficient than regular struct
C typedef struct cannot be nested
D typedef struct allocates memory immediately
Correct Answer:  A. typedef struct creates a named type, eliminating need for 'struct' keyword in declarations
EXPLANATION

typedef creates an alias for the struct type, allowing direct use without 'struct' keyword.

Take Test
What is the output of the following code?
struct Point { int x; int y; };
struct Point p = {5};
printf("%d %d", p.x, p.y);
A 5 0
B 5 garbage
C 0 5
D Compilation error
Correct Answer:  A. 5 0
EXPLANATION

When initializing a struct with fewer values than members, remaining members are zero-initialized. p.x=5, p.y=0.

Take Test
What is the primary advantage of using structures in C?
A To reduce program execution time
B To group related data of different types together
C To automatically initialize variables
D To prevent memory leaks
Correct Answer:  B. To group related data of different types together
EXPLANATION

Structures allow you to combine multiple data types into a single composite type, making code organization and data management more efficient.

Take Test
How do you access a structure member through a pointer in C?
A ptr.member
B ptr->member
C *ptr.member
D &ptr->member
Correct Answer:  B. ptr->member
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. It dereferences the pointer and accesses the member in one operation.

Take Test
What is the purpose of padding in C structures?
A To reduce memory usage
B To align data members on word boundaries for efficient access
C To increase security of the structure
D To prevent structure modification
Correct Answer:  B. To align data members on word boundaries for efficient access
EXPLANATION

Padding adds unused bytes between members to align them on word boundaries, improving CPU access efficiency and performance.

Take Test
Which keyword is used to define a new name for a structure in C?
A define
B typedef
C alias
D rename
Correct Answer:  B. typedef
EXPLANATION

The typedef keyword creates an alias for a data type, allowing you to use a shorter name instead of the full struct declaration.

Take Test
In C, what is a self-referential structure?
A A structure that contains a member pointing to itself
B A structure that calls its own constructor
C A structure with recursive function definitions
D A structure that inherits from itself
Correct Answer:  A. A structure that contains a member pointing to itself
EXPLANATION

A self-referential structure contains a pointer to its own type, commonly used in creating linked lists, trees, and other data structures.

Take Test
IGET
iget AI
Online · Ask anything about exams
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