
Reimplement realloc's grow/shrink pattern with an explicit old size: move a heap block to a buffer of a new size while keeping its leading bytes.
p = malloc(4); /* 'A','B','C','D' */ q = mem_resize(p, 4, 8);Expected result
first 4 bytes of q: ABCDFor your own tracking. Tests grade your code.
p = malloc(8); /* 'A'..'H' */ q = mem_resize(p, 8, 4);Expected result
first 4 bytes of q: ABCDq = mem_resize(NULL, 0, 6); /* like malloc(6) */Expected result
q is a fresh 6-byte blockExpected files
mem-resize.cAllowed functions
mallocfreeAllowed headers
Standard C library
Implements the contract of a function from the standard C library.

v0.40: Create exercises. Challenge the community.
Meet Studio →Reimplement realloc's grow/shrink pattern with an explicit old size: move a heap block to a buffer of a new size while keeping its leading bytes.
p = malloc(4); /* 'A','B','C','D' */ q = mem_resize(p, 4, 8);Expected result
first 4 bytes of q: ABCDFor your own tracking. Tests grade your code.
p = malloc(8); /* 'A'..'H' */ q = mem_resize(p, 8, 4);Expected result
first 4 bytes of q: ABCDq = mem_resize(NULL, 0, 6); /* like malloc(6) */Expected result
q is a fresh 6-byte blockExpected files
mem-resize.cAllowed functions
mallocfreeAllowed headers
Standard C library
Implements the contract of a function from the standard C library.

Run the tests to grade your code
Build your code, then check each test here. Open a result to inspect its output.