wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Memory Allocations in C (Static Memory Allocation)

Total questions: 99

Worksheet time: 50mins

Name
Class
Date
1.

What are the two types of memory allocations possible in C?

a)

(a) Static memory allocation (Compile-time allocation using arrays) (b) Dynamic memory allocation (Run-time allocation using pointers)

b)

(a) Manual memory allocation (User-defined allocation) (b) Automatic memory allocation (System-defined allocation)

c)

(a) Temporary memory allocation (Short-term allocation) (b) Permanent memory allocation (Long-term allocation)

d)

(a) Sequential memory allocation (Ordered allocation) (b) Random memory allocation (Unordered allocation)

2.

In static memory allocation, when is the required amount of memory allocated to the program elements?

a)

At the start of the program

b)

At the end of the program

c)

During program execution

d)

After program termination

3.

If you declare an array of five elements in C and try to read ten elements from it, what will happen?

a)

The program will give an error

b)

Only the first five values will be accessible

c)

The extra elements will be accessible

d)

The program will crash

4.

What is one problem with static memory allocation in C?

a)

If you store less number of elements than the number of elements for which you have declared memory, then the rest of the memory will be wasted.

b)

It allows dynamic resizing of arrays at runtime.

c)

It automatically frees unused memory blocks.

d)

It prevents memory fragmentation completely.

5.

In static memory allocation, the memory allocated to a variable is fixed and determined by the compiler at compile time.

a)

True

b)

False

6.

What is the main advantage of dynamic or run-time memory allocation in programming?

a)

It allows memory to be allocated statically

b)

It allows memory to be allocated as needed at run-time

c)

It reduces the flexibility for programmers

d)

It is only used for static arrays

7.

Which function is used in C to allocate a block of memory in bytes at run-time?

a)

calloc()

b)

malloc()

c)

free()

d)

realloc()

8.

Fill in the blank: The syntax for using malloc to allocate memory is _________.

a)

malloc (number of elements * size of each element);

b)

malloc[number of elements * size of each element];

c)

malloc{number of elements * size of each element};

d)

malloc;

9.

The malloc() function returns a pointer to the first block of allocated memory, and if it fails, it returns NULL.

a)

True

b)

False

10.

In the statement 'int *ptr; ptr = (int *) malloc (10 * sizeof(int));', how many bytes of memory are allocated?

a)

20 bytes

b)

10 bytes

c)

40 bytes

d)

4 bytes

11.

What is the purpose of type casting in the statement 'ptr_var = (type_cast *) malloc (size);'?

a)

To convert the returned pointer (of type void) to the required data type.

b)

To allocate memory for a variable.

c)

To initialize the pointer variable.

d)

To free the allocated memory.

12.

Consider the following code: char *ptr; ptr = (char *) malloc (10 * sizeof(char)); How many elements of type char are being allocated?

a)

10 elements

b)

1 element

c)

5 elements

d)

20 elements

13.

What is the correct syntax to allocate memory for a struct student in C using malloc?

a)

A) st_ptr = malloc(sizeof(struct student));

b)

B) st_ptr = (struct student *) malloc(sizeof(struct student));

c)

C) st_ptr = (struct student *) malloc(struct student);

d)

D) st_ptr = malloc(struct student);

14.

Fill in the blank: After executing the statement st_ptr = (struct student *) malloc(sizeof(struct student));, a contiguous block of memory of size ____ bytes is allocated to st_ptr.

a)

36

b)

24

c)

48

d)

12

15.

What does the malloc() function return if the requested memory cannot be allocated by the system RAM? Choose the correct option.

a)

0

b)

NULL

c)

-1

d)

1

16.

Fill in the blank: The free() function is used to _______ the previously allocated memory using malloc() functions.

a)

de-allocate

b)

allocate

c)

initialize

d)

copy

17.

What is the syntax of the free function in C?

a)

free(ptr_var);

b)

free(ptr);

c)

free(var);

d)

free(memory);

18.

Fill in the blank: Arrays are called ______ data structures because their sizes are predetermined and memory is reserved before processing.

a)

static

b)

dynamic

c)

linked

d)

sequential

19.

Explain one advantage of using linked lists (dynamic data structures) over arrays (static data structures) as described in the passage.

a)

Linked lists allow easy insertion and deletion of elements without shifting other elements.

b)

Linked lists use less memory than arrays for all types of data.

c)

Arrays are always faster than linked lists for searching elements.

d)

Arrays can grow and shrink in size more easily than linked lists.

20.

What is a linked list?

a)

A linear collection of data elements, called node pointing to the next nodes by means of pointers.

b)

A collection of arrays.

c)

A type of tree structure.

d)

A single data element.

21.

What is the info value stored in Node-2?

a)

20

b)

10

c)

30

d)

40

22.

Which of the following is NOT a basic operation on linked lists?

a)

A) Creation

b)

B) Insertion

c)

C) Multiplication

d)

D) Deletion

23.

Insertion in a linked list can be performed at which of the following positions?

a)

At the beginning

b)

At the end

c)

At a specified position

d)

All of the above

24.

Fill in the blank: If the list itself is empty, then the new node is inserted as a ______ node.

a)

first

b)

last

c)

middle

d)

head

25.

Deletion in a linked list can be performed from the beginning, end, or specified position.

a)

True

b)

False

26.

Forward traversing in a linked list refers to:

a)

Visiting each node from the head to the tail.

b)

Visiting each node from the tail to the head.

c)

Skipping alternate nodes in the list.

d)

Reversing the order of nodes in the list.

27.

Reverse traversing in a linked list refers to:

a)

Visiting the nodes from the last node to the first node.

b)

Visiting the nodes from the first node to the last node.

c)

Deleting nodes from the end of the list.

d)

Inserting nodes at the beginning of the list.

28.

Which of the following is NOT a type of linked list?

a)

Singly linked list

b)

Doubly linked list

c)

Circular linked list

d)

Binary linked list

29.

Fill in the blank: A ________ linked list is also called a linear linked list.

a)

singly

b)

doubly

c)

circular

d)

header

30.

In a singly linked list, you can access the predecessor node directly from the current node.

a)

True

b)

False

31.

What is the link value of Node-3 in the singly linked list diagram?

a)

0

b)

1

c)

2

d)

3

32.

The main advantage of a doubly linked list over a singly linked list is:

a)

It allows traversal in both directions.

b)

It uses less memory than a singly linked list.

c)

It is easier to implement than a singly linked list.

d)

It does not require pointers.

33.

What is the info value stored in Node-2?

a)

2

b)

4

c)

6

d)

1000

34.

What is the address stored in the link field of Node-3?

a)

1000

b)

2000

c)

3000

d)

0

35.

Fill in the blank: A circular linked list is one which has no _______ and no _______.

a)

beginning, end

b)

head, tail

c)

nodes, links

d)

data, pointer

36.

A singly linked list can be made circular by:

a)

Linking the last node to the first node

b)

Linking the first node to the last node

c)

Removing the head node

d)

Linking every node to itself

37.

What is a circular doubly linked list?

a)

A list with only successor pointers

b)

A list with only predecessor pointers

c)

A list with both successor and predecessor pointers in circular manner

d)

A list with random pointers

38.

What is the INFO value of Node-2?

a)

2

b)

4

c)

6

d)

8

39.

Refer to Fig. (4). A Circular Doubly Linked List. Fill in the blank: The address of the right pointer of Node-3 is _______.

a)

1000

b)

2000

c)

3000

d)

4000

40.

Which step in the algorithm to insert a node at the beginning of a singly linked list sets the LINK of the new node?

a)

Step 2

b)

Step 3

c)

Step 4

d)

Step 5

41.

Fill in the blank: Before inserting the first node in the singly linked list, START = _______.

a)

NULL

b)

0

c)

START

d)

FIRST

42.

What is the purpose of the 'insert_beg()' function in the context of singly linked lists?

a)

To delete a node from the beginning

b)

To insert a node at the beginning

c)

To search for a node

d)

To reverse the linked list

43.

Function to insert node at the beginning of the singly linked list: In the 'insert_beg()' function, which statement allocates memory for the new node?

a)

A) ptr=(list *)malloc(sizeof(list));

b)

B) ptr->info=num;

c)

C) start=ptr;

d)

D) scanf("%d,&num);

44.

What is the initial value of START before inserting the first node in the singly linked list? Fill in the blank: START = _____.

a)

NULL

b)

0

c)

START

d)

1

45.

Algorithm to insert node at the end of the singly linked list: Which step in the algorithm sets the INFO part of the new node?

a)

Step 1

b)

Step 2

c)

Step 3

d)

Step 4

46.

What does the TEMP pointer do in the algorithm for inserting a node at the end of the singly linked list?

a)

It traverses the list to find the last node.

b)

It stores the value to be inserted.

c)

It points to the head of the list.

d)

It deletes the last node.

47.

Function to insert node at the beginning of the singly linked list: True or False: The statement 'ptr->link=start;' in the 'insert_beg()' function sets the new node's link to point to the previous first node.

a)

True

b)

False

48.

Algorithm to insert node at the end of the singly linked list: Fill in the blank: The link part of the new node is set to _____ in Step 4.

a)

NULL

b)

HEAD

c)

PREV

d)

START

49.

What is the purpose of the 'temp' pointer in the function to insert a node at the end of a singly linked list?

a)

To store the value to be inserted

b)

To traverse the list to the last node

c)

To allocate memory for the new node

d)

To delete a node

50.

In the function to insert a node at the end of a singly linked list, the statement 'ptr->link = ____;' sets the link of the new node to

a)

NULL

b)

head

c)

ptr

d)

temp

51.

Algorithm to insert node at a specific location in the singly linked list: According to the algorithm, what happens if the location LOC is greater than the total number of nodes in the list?

a)

The node is inserted at the end

b)

The node is inserted at the beginning

c)

The node cannot be inserted and an error message is shown

d)

The node is inserted at the specified location anyway

52.

Before inserting the first node in the singly linked list, the value of START is set to ____ and F is set to 0.

a)

NULL

b)

0

c)

1

d)

START

53.

What is the purpose of Step 3 in the algorithm for inserting a node in a singly linked list?

a)

To delete a node

b)

To allocate memory for the new node

c)

To read the value to be inserted

d)

To set the link of the new node

54.

What is the purpose of the 'insert_spe' function in the given code?

a)

To insert a special element into a data structure.

b)

To delete a specific element from a list.

c)

To update the value of a variable.

d)

To sort the elements in an array.

55.

In the code, which statement is used to allocate memory for the new node?

a)

ptr = (list *)malloc(sizeof(list));

b)

temp = start;

c)

ptr->info = num;

d)

temp = temp->link;

56.

Fill in the blank: In the algorithm, if LOC is equal to 1, the new node's LINK is set to _______.

a)

START

b)

NULL

c)

END

d)

HEAD

57.

What is the first step in the algorithm to delete a node from the beginning of a singly linked list?

a)

Check if START is NULL, then write "List is empty" and return.

b)

Move the START pointer to the next node.

c)

Delete the last node in the list.

d)

Insert a new node at the beginning.

58.

Why is it important to deallocate memory of the node at the beginning of the singly linked list?

a)

To prevent memory leaks

b)

To increase the size of the linked list

c)

To make the node accessible again

d)

To speed up the insertion process

59.

What does the function delete_beg() do in a singly linked list?

a)

It deletes the node at the beginning of the singly linked list and frees its memory.

b)

It deletes the node at the end of the singly linked list and frees its memory.

c)

It inserts a node at the beginning of the singly linked list.

d)

It reverses the singly linked list.

60.

In the function delete_beg(), what is printed if the list is empty?

a)

The deleted element from the beginning of singly linked list is : %d

b)

List is empty

c)

Memory deallocated

d)

Node deleted

61.

In the algorithm to delete a node from the beginning of a singly linked list, which pointer is used to deallocate memory?

a)

A) START

b)

B) PTR

c)

C) LINK

d)

D) INFO

62.

What does the algorithm do if the list is empty?

a)

It writes 'List is empty' and returns.

b)

It sorts the list and continues.

c)

It adds a default value to the list.

d)

It throws an error and stops.

63.

What is the value of START after deleting the only node in the list?

a)

NULL

b)

0

c)

1

d)

START

64.

What does NUM represent in the algorithm?

a)

NUM represents the information part of the deleted node.

b)

NUM represents the address of the next node.

c)

NUM represents the total number of nodes in the list.

d)

NUM represents the position of the head node.

65.

Function to delete node from the end of the singly linked list void delete_end() What is printed if the list is empty?

a)

A) List is empty

b)

B) Deleted element from the end

c)

C) NULL

d)

D) Error

66.

Function to delete node from the end of the singly linked list Which pointer is used to traverse the list to the last node?

a)

A) start

b)

B) temp

c)

C) ptr

d)

D) num

67.

What does PTR represent in the algorithm to delete a node from a specific location in the singly linked list?

a)

The address of the first node

b)

The structure pointer which deallocates memory of the node

c)

The element to be deleted

d)

The link to the next node

68.

In the algorithm to delete a node from a specific location in the singly linked list, what is the first step if START is NULL?

a)

Set PTR := START

b)

Write: 'List is empty' and return

c)

Read the location LOC

d)

Set NUM := PTR->INFO

69.

Fill in the blank: In the algorithm, TEMP is a structure pointer to modify the ______ part of the previous node.

a)

LINK

b)

DATA

c)

HEAD

d)

TAIL

70.

Which step in the algorithm reads the location LOC from where you want to delete the node?

a)

Step 1

b)

Step 2

c)

Step 3

d)

Step 4

71.

In the algorithm, if PTR is NULL during the loop, it means the total nodes in the list are less than the given position.

a)

True

b)

False

72.

What is written in Step 6 of the algorithm to delete a node from a specific location in the singly linked list?

a)

'List is empty' and return

b)

'Total nodes in the list are less than this position'

c)

'Deleted element from the singly linked list :', NUM

d)

'So node cannot be deleted' and return

73.

Fill in the blank: Step 8 of the algorithm is to ______.

a)

Exit

b)

Continue

c)

Repeat

d)

Start

74.

What is the purpose of the function 'delete_spe()' in the given code snippet?

a)

To insert a node at a specific location in a singly linked list

b)

To delete a node from a specific location in a singly linked list

c)

To search for a node in a singly linked list

d)

To reverse a singly linked list

75.

Fill in the blank: In the function 'delete_spe()', if 'start' is NULL, the function prints 'List is empty' and _______.

a)

returns

b)

continues

c)

exits

d)

loops

76.

What happens in the function 'delete_spe()' if the location entered by the user is 1?

a)

The first node in the list is deleted.

b)

The last node in the list is deleted.

c)

No node is deleted.

d)

A new node is added at the first position.

77.

In the function 'delete_spe()', if the entered location is greater than the number of nodes in the list, the function prints 'Total nodes in the list are lesser than this position.' and 'So node cannot be deleted'.

a)

True

b)

False

78.

Fill in the blank: After deleting the node, the function prints 'The deleted element from the singly linked list is : %d', where %d is replaced by _______.

a)

the value of num, which is ptr->info (the deleted node's info)

b)

the address of the deleted node

c)

the total number of nodes in the list

d)

the value of the next node's info

79.

What is the purpose of the 'initialize()' function in the singly linked list program?

a)

To insert a node at the beginning

b)

To set up the initial state of the list

c)

To delete a node

d)

To traverse the list

80.

Which function is used to insert a node at the beginning of the singly linked list?

a)

insert_end()

b)

insert_beg()

c)

insert_spe()

d)

delete_beg()

81.

Fill in the blank: The function used to delete a node from the end of the singly linked list is ________.

a)

delete_end()

b)

delete_start()

c)

insert_end()

d)

insert_start()

82.

Which menu option allows you to traverse the singly linked list?

a)

1

b)

4

c)

7

d)

8

83.

Fill in the blank: The function 'insert_spe()' is used for ________ in the singly linked list.

a)

insertion at a specific location

b)

deletion at the end

c)

searching for a node

d)

reversing the list

84.

What does the 'delete_spe()' function do in the singly linked list program?

a)

Deletes the first node

b)

Deletes the last node

c)

Deletes a node from a specific location

d)

Traverses the list

85.

Which header file is NOT included in the singly linked list program?

a)

A) stdio.h

b)

B) conio.h

c)

C) stdlib.h

d)

D) string.h

86.

What is the purpose of the 'initialize' function in the given code snippet?

a)

To insert a node at the beginning of the singly linked list

b)

To set the start pointer to NULL

c)

To delete a node from the singly linked list

d)

To traverse the singly linked list

87.

Which function is called when the user selects choice 1 in the switch-case menu?

a)

insert_end()

b)

insert_spe()

c)

insert_beg()

d)

delete_beg()

88.

Fill in the blank: In the 'insert_beg' function, the statement 'ptr->link = ____;' links the new node to the existing list.

a)

start

b)

NULL

c)

head

d)

temp

89.

What is the purpose of the function 'insert_end()' in the given code?

a)

To delete a node from the singly linked list

b)

To insert a node at the end of the singly linked list

c)

To search for a node in the singly linked list

d)

To insert a node at the beginning of the singly linked list

90.

What does the following line of code do in the 'insert_end()' function? ptr=(list *)malloc(sizeof(list));

a)

Allocates memory for a new node

b)

Frees memory of a node

c)

Initializes the start pointer

d)

Links two nodes together

91.

What is the purpose of the function 'insert_spe()' in the given code?

a)

To insert a node at the end of the singly linked list

b)

To insert a node at a specific location in the singly linked list

c)

To delete a node from the singly linked list

d)

To reverse the singly linked list

92.

Fill in the blank: In the 'insert_spe()' function, the variable 'loc' represents the ______ where the new node should be inserted.

a)

location

b)

value

c)

pointer

d)

index

93.

What is the purpose of the function 'delete_beg()' in the context of singly linked lists?

a)

To insert a node at the beginning

b)

To delete a node from the beginning

c)

To delete a node from the end

d)

To search for a node

94.

Fill in the blank: The function 'delete_end()' is used to delete a node from the ______ of the singly linked list.

a)

end

b)

beginning

c)

middle

d)

head

95.

What will be printed if 'delete_beg()' is called when the list is empty?

a)

List is empty

b)

0

c)

Segmentation fault

d)

Node deleted

96.

The role of 'ptr' in the 'delete_beg()' function for singly linked lists is:

a)

to point to the first node to be deleted

b)

to store the value of the last node

c)

to count the number of nodes in the list

d)

to insert a new node at the beginning

97.

What is the purpose of the function 'delete_spe()' in the given C code for singly linked lists?

a)

To insert a node at a specific location

b)

To delete a node from a specific location

c)

To search for a node

d)

To display the list

98.

In the given code, what will be printed if 'start' is NULL when 'delete_spe()' is called?

a)

List is empty

b)

Node deleted

c)

Invalid location

d)

No output

99.

Fill in the blank: In the function to delete the last node from a singly linked list, the statement 'temp->link=____;' is used to remove the last node.

a)

NULL

b)

temp

c)

head

d)

0