estion #4 please. Given code in lab #include #include /* Test that memory is properly de-allocated by using valgrind to execture * * To compile: gcc lab4b.c * * To execute: ./a.out * * To execute with valgrind tool: valgrind ./a.out */
Solve question #4 please.
Given code in lab
#include <stdio.h>
#include <stdlib.h>
/* Test that memory is properly de-allocated by using valgrind to execture
*
* To compile: gcc lab4b.c
*
* To execute: ./a.out
*
* To execute with valgrind tool: valgrind ./a.out
*/
int main (int argc, char** argv)
{
int i;
/* allocation and use of a dynamic ONE dimenstional array */
/* variable declararion */
int* arr1;
/* allocate space for 20 intergers */
arr1 = (int*) malloc (sizeof(int) * 20 );
/* initialize all array locations to contain the value zero */
for ( i = 0 ; i < 20 ; i++ )
arr1[i] = 0;
/* print out all of the values */
for ( i = 0 ; i < 20 ; i++ )
printf ("Position: %3d, value: %3d\n", i, arr1[i]);
/* de-allocated the memory for the array when finished */
free (arr1);
return 0;
}
Thanks in Advance. :)
I have solved 4 and 5 as per the given description.
Step by step
Solved in 3 steps with 1 images