Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 291
Topics in C Programming
Q.51 Easy Dynamic Memory
How much memory is allocated by malloc(sizeof(int) * 10) on a 32-bit system where sizeof(int) = 4?
A 10 bytes
B 40 bytes
C 4 bytes
D 44 bytes
Correct Answer:  B. 40 bytes
EXPLANATION

sizeof(int) * 10 = 4 * 10 = 40 bytes on a 32-bit system.

Test
Q.52 Easy Dynamic Memory
Which function is used to free dynamically allocated memory?
A delete()
B release()
C free()
D unalloc()
Correct Answer:  C. free()
EXPLANATION

free() is the standard function to deallocate memory previously allocated by malloc(), calloc(), or realloc().

Test
Q.53 Easy Dynamic Memory
What does calloc() do differently from malloc()?
A Allocates more memory
B Initializes memory to zero
C Allocates memory faster
D Returns integer instead of void pointer
Correct Answer:  B. Initializes memory to zero
EXPLANATION

calloc() takes two arguments (number of elements and size) and initializes all allocated bytes to zero, unlike malloc().

Test
Q.54 Easy Dynamic Memory
Which header file is required for dynamic memory allocation functions?
A
B
C
D
Correct Answer:  B.
EXPLANATION

The <stdlib.h> header file contains declarations for malloc(), calloc(), realloc(), and free() functions.

Test
Q.55 Easy File Handling
In a file processing application, what is the primary difference between 'wb' and 'w' file modes?
A 'wb' opens in binary mode while 'w' opens in text mode
B 'w' is faster than 'wb'
C 'wb' allows reading while 'w' does not
D There is no difference in modern C compilers
Correct Answer:  A. 'wb' opens in binary mode while 'w' opens in text mode
EXPLANATION

'w' opens file in text mode (converts line endings), while 'wb' opens in binary mode (no conversion). This matters when handling platform-specific line endings (\r\n vs \n).

Test
Q.56 Easy File Handling
Which function is used to check if the end-of-file (EOF) has been reached in C file handling?
A feof(fp)
B eof(fp)
C iseof(fp)
D checkeof(fp)
Correct Answer:  A. feof(fp)
EXPLANATION

feof() is the standard C library function that returns non-zero if EOF has been reached on the given file stream. Other options are not valid C functions.

Test
Q.57 Easy File Handling
Which mode opens file in text format with write permission only?
A wb
B w
C wt
D wa
Correct Answer:  B. w
EXPLANATION

'w' mode opens file in text format for writing. 'wb' is binary write. 'wt' is explicitly text write but 'w' is default text mode.

Test
Q.58 Easy File Handling
Which function returns the current position of file pointer?
A fgetpos()
B ftell()
C fseek()
D rewind()
Correct Answer:  B. ftell()
EXPLANATION

ftell() returns the current file position as a long integer. fgetpos() stores position in a fpos_t structure. rewind() resets to beginning.

Test
Q.59 Easy File Handling
What does fseek(fp, 0, SEEK_END) accomplish?
A Moves pointer to beginning of file
B Moves pointer to end of file
C Moves pointer to current position
D Closes the file pointer
Correct Answer:  B. Moves pointer to end of file
EXPLANATION

SEEK_END moves the file pointer to the end of file. SEEK_SET goes to beginning, SEEK_CUR to current position.

Test
Q.60 Easy File Handling
Which file opening mode allows both reading and writing without truncating existing content?
A r+
B w+
C a+
D x+
Correct Answer:  A. r+
EXPLANATION

Mode 'r+' opens file for reading and writing without truncating. 'w+' truncates the file, 'a+' appends, and 'x+' is for exclusive creation.

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