Question: 1. Write a function create_array with the following prototype: int * create_array (int n, int initial_value); The function should return a pointer to a dynamically
1. Write a function create_array with the following prototype:
int * create_array (int n, int initial_value);
The function should return a pointer to a dynamically allocated array of integer values, with n elements, each of which is initialized to initial_value. The function should print an error message and return NULL if the array cannot be allocated.
2. Write a program that uses the above function as follows:
The program asks the user to enter the size of the array and the initial values.
The program then calls the create_array function to create the new array. The program should exit with an error code if the function fails to allocate the array.
Once the array is created, the program should save the array in a binary file called arrayb.dat.
3. Check the contents of your binary file with the xxd binary file viewer:
>xxd b c 4 arrayb.dat
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
