wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DAY 9 File Handling & Dynamic Memory Allocation - 20th JUNE 24

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the primary function of fopen() in C programming?

a)

To open a file for reading

b)

To allocate memory dynamically

c)

To close a file

d)

To delete a file

2.

Which mode in fopen() allows both reading and writing to a file without truncating it?

a)

"r"

b)

"w"

c)

"a"

d)

"r+"

3.

How do you close a file in C using fclose()?

a)

fclose(file);

b)

close(file);

c)

closeFile(file);

d)

file.close();

4.

What will feof() return when the end of file is reached in C?

a)

0

b)

1

c)

-1

d)

NULL

5.

How do you read a character from a file in C using fgetc()?

a)

fgetc(file);

b)

readChar(file);

c)

getChar(file);

d)

file.getc();

6.

Which function is used to dynamically allocate memory in C?

a)

malloc()

b)

allocate()

c)

new()

d)

calloc()

7.

What will malloc() return if it fails to allocate memory?

a)

NULL

b)

-1

c)

0

d)

1

8.

How do you allocate memory for an integer variable in C using malloc()?

a)

malloc(sizeof(int));

b)

malloc(sizeof(int*));

c)

malloc(int);

d)

malloc(int*);

9.

How do you release dynamically allocated memory in C using free()?

a)

releaseMemory(ptr);

b)

deleteMemory(ptr);

c)

free(ptr);

d)

delete(ptr);

10.

What does calloc() do in C programming?

a)

Allocates memory and initializes it to zero

b)

Allocates memory without initialization

c)

Frees allocated memory

d)

Resizes allocated memory