Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following 3 code fragments: 1) int *ptr = malloc (sizeof(int)*3); p

ID: 3721956 • Letter: C

Question


Consider the following 3 code fragments: 1) int *ptr = malloc (sizeof(int)*3); ptr[0] = 0; ptr[1] 0; ptr[2] " 0; 2) int ptr - calloc (3, sizeof (int)) if (ptr== NULL){ printf ("Unable to allocate memory. In") exit (1): 3) int iptr= calloc ( 1 , sizeof (int)); if (ptr-NULL) { printf("Unable to allocate memory.In") exit (1) ptr realloc (ptr, 3 sizeof (int)) if (ptrNULL) printf("Unable to allocate memory.In") exit (1) Dynamic allocation of an integer array of size 3 with elements initialized to O is safely done in code fragment(s):

Explanation / Answer

Let me tell you what is fragmentation?

Fragmentation is a term which refers to storage space that has not been organized/utilized properly and hence, it therefore reduces the performance of a device/system.

Types of fragmentation:

Case study of internal fragmentation:

A memory is allocated in the form which is a factor of 4, 8, or the 16 bytes.

Now consider that a currently runnning process requires 21 bytes , it will be allocated nearest factor of multiple which is 24 bytes.

In such a situation, extra memory allocated will be squandered.

Required memory is 21, allocated memory is 24.

Hence 24-21=3 bytes is a padding block. (It is extra and results in Internal fragmentation)

Therefore, the correcty answer is

i.e,

Adding padding to a block to meet the double-word alignment requirement (leads to internal fragmentation).

#NOTE: The answer is accurate with best possible explanation and hence is it recommended to give comment/feedback. Thanks in advance.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote