NEW
Font size
WorksheetsDAY 9 File Handling & Dynamic Memory Allocation - 20th JUNE 24
Total questions: 10
Worksheet time: 5mins
What is the primary function of fopen() in C programming?
To open a file for reading
To allocate memory dynamically
To close a file
To delete a file
Which mode in fopen() allows both reading and writing to a file without truncating it?
"r"
"w"
"a"
"r+"
How do you close a file in C using fclose()?
fclose(file);
close(file);
closeFile(file);
file.close();
What will feof() return when the end of file is reached in C?
0
1
-1
NULL
How do you read a character from a file in C using fgetc()?
fgetc(file);
readChar(file);
getChar(file);
file.getc();
Which function is used to dynamically allocate memory in C?
malloc()
allocate()
new()
calloc()
What will malloc() return if it fails to allocate memory?
NULL
-1
0
1
How do you allocate memory for an integer variable in C using malloc()?
malloc(sizeof(int));
malloc(sizeof(int*));
malloc(int);
malloc(int*);
How do you release dynamically allocated memory in C using free()?
releaseMemory(ptr);
deleteMemory(ptr);
free(ptr);
delete(ptr);
What does calloc() do in C programming?
Allocates memory and initializes it to zero
Allocates memory without initialization
Frees allocated memory
Resizes allocated memory
