Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 151–160 of 490
Topics in C Programming
Q.151 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.

Test
Q.152 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.

Test
Q.153 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.

Test
Q.154 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.

Test
Q.155 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.

Test
Q.156 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.

Test
Q.157 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).

Test
Q.158 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).

Test
Q.159 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.

Test
Q.160 Medium Structures & Unions
In a nested structure scenario like struct A contains struct B, how do you access a member of B from A's variable?
A a_var->b_member
B a_var.b_var.c_member
C Both A and B are correct depending on context
D a_var..c_member
Correct Answer:  C. Both A and B are correct depending on context
EXPLANATION

If B is embedded in A: a_var.b_var.member. If B is a pointer in A: a_var->b_var->member or a_var.b_ptr->member.

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