Which of the following statements about structures is TRUE?
Answer: B
A structure allows grouping of different data types. Padding may be added by the compiler for alignment.
Q.202Easy
Consider the following code:
struct Data {
int a;
char b;
};
struct Data d = {10, 'A'};
Which method of initialization is used here?
Answer: B
Values are assigned in the order they appear in the structure definition, which is positional initialization.
Q.203Easy
What is the primary difference between a struct and a union in C?
Answer: A
In a union, all members occupy the same memory space, while struct members have individual memory locations.
Q.204Easy
Which of the following correctly demonstrates accessing a member of a pointer to a structure?
Answer: B
Both (*ptr).member and ptr->member are valid. Option B uses explicit dereferencing, while the arrow operator is syntactic sugar for this.
Q.205Easy
In C, what does the 'typedef' keyword do when used with structures?
Answer: A
typedef creates an alias, allowing you to use the structure name directly without using 'struct' keyword.
Advertisement
Q.206Easy
Given: struct Node { int data; struct Node *next; }; This represents which data structure concept?
Answer: B
A self-referential structure with a single pointer member is the fundamental building block of a singly linked list.
Q.207Easy
In the context of structures, what does 'self-referential' mean?
Answer: A
Self-referential structures contain pointers to their own type, enabling dynamic data structures like linked lists and trees.
Q.208Easy
What is the key difference between a structure and a union in C?
Answer: B
In structures, memory is allocated for each member independently. In unions, all members share the same memory location, so total memory allocated equals the size of the largest member.
Q.209Easy
struct Node { int data; struct Node *next; }; This is an example of which design pattern?
Answer: B
A self-referential structure contains a pointer to its own type. This is the fundamental building block for creating linked lists, trees, and other dynamic data structures.
Q.210Easy
Given a structure with array members, how would you efficiently pass it to a function to avoid copying overhead?
Answer: B
Passing a pointer to the structure avoids copying the entire structure in memory, which is especially important for large structures with array members. This improves performance significantly.
Q.211Easy
Which function is used to open a file in C?
Answer: A
fopen() is the standard C library function used to open a file. It takes two arguments: filename and mode.
Q.212Easy
What does the mode 'rb' mean in fopen()?
Answer: A
'rb' mode opens a file for reading in binary format. Binary mode reads the exact bytes without any text conversion.
Q.213Easy
Which function is used to close a file in C?
Answer: A
fclose() is the standard function to close an opened file stream. It returns 0 on success and EOF on error.
Q.214Easy
Which mode opens a file for writing and truncates it if it exists?
Answer: A
"w" mode opens a file for writing. If the file exists, it truncates the file to zero length. If it doesn't exist, a new file is created.
Q.215Easy
When opening a file in 'w' mode, what happens if the file already exists?
Answer: A
Opening a file in 'w' mode truncates the file to zero length if it exists, discarding all previous content.
Q.216Easy
Which of the following file modes in fopen() allows reading only?
Answer: B
The 'r' mode opens a file for reading only. The file must exist, otherwise fopen() returns NULL.
Q.217Easy
In file handling, what does the 'b' flag in file modes like 'rb' or 'wb' indicate?
Answer: A
The 'b' flag specifies binary mode, which prevents any translation of line endings or special characters.
Q.218Easy
Which function is used to determine the current position in a file?
Answer: A
ftell() returns the current position (as a long integer) of the file pointer in the file. fseek() is used to change position, rewind() resets to beginning, and fgetpos() stores position in a structure.
Q.219Easy
What is the correct syntax to open a file named 'data.txt' in read mode?
Answer: B
fopen() uses double quotes for string arguments in C. The first argument is filename and second is mode. Single quotes are for characters, not strings.
Q.220Easy
Which mode allows both reading and writing to a file, creating it if it doesn't exist?
Answer: B
"w+" opens file for reading and writing, truncating it if it exists, and creating it if it doesn't. "r+" requires file to exist. "a+" opens in append mode with read capability.