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. :)

![Q3
For Questions 3-4: Consider the following code from lab4b.c. This code uses a pointer to a one
dimensional array of type int.
// variable declaration
int*
arr1;
// allocate space for 20 integers
arri = (int *) malloc ( sizeof (int) * 20 );
// initialize all array locations to zero
for (int i = 0 ; i < 20 ; i++ )
arr1[i] = e;
// de-allocating the memory when finished
free (arr1);
Q3.1
Write the C variable declaration for a pointer to a dynamically allocated two dimensional array
of type int. To access a value in the 2D array, the variable must be able to use two square
bracket operators such as:
arr2d[i][j] = x;
int **arr2d;
Q4
Q4.1
Using the varaible declared in Q3, write the C malloc code that would allocate memory for a 2D
array of 20x30 integers and store them into the array from Q3.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F672bf286-8abe-4b07-9ca1-0d5b2612956c%2F8570c055-cad8-4d5c-9d9d-67599384852e%2Fx010htd_processed.png&w=3840&q=75)

I have solved 4 and 5 as per the given description.
Step by step
Solved in 3 steps with 1 images









