#include <stdio.h> #include <stdlib.h> void print_arr(int nums[], int esize); in
ID: 3591522 • Letter: #
Question
#include <stdio.h>
#include <stdlib.h>
void print_arr(int nums[], int esize);
int main ()
{
printf(" ");
const int SIZE = 4;
// dynamically allocate an array of size SIZE
int* vals = (int*)malloc(sizeof(int) * SIZE);
// fill the array with values
int i;
for (i = 0; i < SIZE; ++i)
???? = 2*i;
// call the print_arr function
print_arr(????);
// do not forget to give it back
????
printf(" ");
return 0;
}
void print_arr(int nums[], int esize)
{
printf(" ");
int i;
for (i = 0; i < esize; ++i)
printf("*(nums + %d) = %d ", i, *(nums + i));
printf(" ");
}
Explanation / Answer
//Please see the updated code and output below , Please do thumbs up if you like the solution
#include <stdio.h>
#include <stdlib.h>
void print_arr(int nums[], int esize);
int main ()
{
printf(" ");
const int SIZE = 4;
// dynamically allocate an array of size SIZE
int* vals = (int*)malloc(sizeof(int) * SIZE);
// fill the array with values
int i;
for (i = 0; i < SIZE; ++i)
*(vals+i) = 2*i;
// call the print_arr function
print_arr(vals,SIZE);
// do not forget to give it back
free(vals);
printf(" ");
return 0;
}
void print_arr(int nums[], int esize)
{
printf(" ");
int i;
for (i = 0; i < esize; ++i)
printf("*(nums + %d) = %d ", i, *(nums + i));
printf(" ");
}
OUTPUT:
*(nums + 0) = 0
*(nums + 1) = 2
*(nums + 2) = 4
*(nums + 3) = 6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.