Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 151–160 of 499
Topics in C Programming
Q.151 Medium File Handling
Which function sets the file position to a specific location?
A fseek()
B setpos()
C fsetpos()
D seek()
Correct Answer:  A. fseek()
EXPLANATION

fseek() is used to move the file pointer to a specific position in the file. It takes three arguments: file pointer, offset, and origin.

Take Test
Q.152 Medium File Handling
What is the purpose of ftell() function?
A Returns current file position
B Tells if file exists
C Tells file name
D Tells file size
Correct Answer:  A. Returns current file position
EXPLANATION

ftell() returns the current position of the file pointer in bytes from the beginning of the file.

Take Test
Q.153 Medium File Handling
Which function writes formatted data to a file?
A fprintf()
B fwrite()
C fputs()
D fputc()
Correct Answer:  A. fprintf()
EXPLANATION

fprintf() writes formatted data to a file, similar to printf() but with a file pointer as the first argument.

Take Test
Q.154 Medium File Handling
What does fgets() function do?
A Reads a line from a file
B Gets file status
C Gets file size
D Gets file pointer position
Correct Answer:  A. Reads a line from a file
EXPLANATION

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.

Take Test
Q.155 Medium Structures & Unions
Which of the following statements about structure initialization in C is INCORRECT?
A Designated initializers allow setting members in any order
B All members must be explicitly initialized during declaration
C Members can be initialized during structure definition
D Partial initialization results in uninitialized members having indeterminate values
Correct Answer:  B. All members must be explicitly initialized during declaration
EXPLANATION

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.

Take Test
Q.156 Medium Structures & Unions
In the context of bit fields in structures, what is the maximum number of bits that can be allocated to a single member in standard C?
A 8 bits
B 16 bits
C Size of the underlying type in bits
D 32 bits
Correct Answer:  C. Size of the underlying type in bits
EXPLANATION

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.

Take Test
Q.157 Medium Structures & Unions
Which feature in C allows you to define a structure without a tag name for use within another structure?
A Tagged union
B Anonymous structure
C Typedef structure
D Nested enumeration
Correct Answer:  B. Anonymous structure
EXPLANATION

Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.

Take Test
Q.158 Medium Structures & Unions
Consider the following code:
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?
A 13 bytes
B 16 bytes
C 20 bytes
D 24 bytes
Correct Answer:  D. 24 bytes
EXPLANATION

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

Take Test
Q.159 Medium Structures & Unions
Consider this structure: struct Complex { int real; int imag; }; If you want to create an array of 100 such structures, which declaration is correct?
A struct Complex c[100];
B struct Complex *c = (struct Complex *)malloc(100);
C struct Complex c = {100};
D struct Complex c[100][100];
Correct Answer:  A. struct Complex c[100];
EXPLANATION

Option A correctly creates a static array of 100 structures. Option B creates a pointer (and allocates incorrect size).

Take Test
Q.160 Medium Structures & Unions
What is the purpose of using anonymous structures/unions?
A To reduce memory usage
B To access members without using the intermediate struct name
C To improve execution speed
D To hide members from external access
Correct Answer:  B. To access members without using the intermediate struct name
EXPLANATION

Anonymous structures allow direct member access without needing to reference the nested structure name.

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