Govt Exams
fseek() is used to move the file pointer to a specific position in the file. It takes three arguments: file pointer, offset, and origin.
ftell() returns the current position of the file pointer in bytes from the beginning of the file.
fprintf() writes formatted data to a file, similar to printf() but with a file pointer as the first argument.
fgets() reads a string from a file until a newline character or end of file is encountered. It takes three arguments: buffer, size, and file pointer.
Members do not need to be explicitly initialized. Uninitialized members in automatic structures have indeterminate values, while static structures have zero-initialized members. Designated initializers (C99+) allow flexible initialization order.
The maximum number of bits for a bit field member cannot exceed the size of the underlying type. For int (typically 32 bits), you can allocate up to 32 bits to a single member.
Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.
struct Data {
int x;
char y;
double z;
};
Assuming int=4 bytes, char=1 byte, double=8 bytes, what is the size of struct Data due to padding?
Memory alignment causes padding. x(4) + padding(4) + y(1) + padding(7) + z(8) = 24 bytes. The compiler aligns to the largest member (double = 8 bytes).
Option A correctly creates a static array of 100 structures. Option B creates a pointer (and allocates incorrect size).
Anonymous structures allow direct member access without needing to reference the nested structure name.