For this program you will declare some variables in main, call a function do_som
ID: 3574654 • Letter: F
Question
For this program you will declare some variables in main, call a function do_something and print out some results.
declare a constant SIZE outside of main and initialize it to 6.
in main:
Declare an dynamic array of pointers to doubles of size SIZE. Call the array dynamic_arr_ptrs_to_dbl.
Declare an alias to the array called dynamic_arr_ptrs_to_dbl_alias.
Declare a pointer to an integer called size_ptr and initialize it to be a reference to SIZE.
Declare a static array of doubles called static_arr_ptrs_to_dbl of size SIZE and initialize it to:
{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }
Call a function do_something using the call:
double **returned_pointer = do_something (dynamic_arr_ptrs_to_dbl_alias, static_arr_ptrs_to_dbl, size_ptr);
After to call, print out the doubles in the dynamic array returned by do_somehting as follows (It is not necessary to show the decimal point and two zeros):
Element 0 is 1.00
Element 1 is 2.00
Element 2 is 3.00
Element 3 is 4.00
Element 4 is 5.00
Element 5 is 6.00
Press any key to continue . . .
Outside of main:
Create a definition of the function do_something.
Inside the function:
Set the first group of 3 elements of the dynamic array to references to the first three elements of the static array using pointer notation for array accesses.
Set the second group of 3 elements of the dynamic array to references to the second 3 elements of the static array using square bracket notation for array accesses.
Explanation / Answer
#include<stdio.h>
#define SIZE 6
do_something(double *dynamic_arr_ptrs_to_dbl_alias[], double static_arr_ptrs_to_dbl[], int *size_ptr){
}
int main()
{
int i;
double *dynamic_arr_ptrs_to_dbl[SIZE];
for(i=0; i< SIZE ;i++)
dynamic_arr_ptrs_to_dbl[i] = malloc(sizeof(double));
tydef dynamic_arr_ptrs_to_dbl dynamic_arr_ptrs_to_dbl_alias;
int *size_ptr = SIZE;
double static_arr_ptrs_to_dbl[SIZE] = {1.0,2.0,3.0,4.0,.5.0,6.0};
double **returned_pointer = do_something(dynamic_arr_ptrs_to_dbl_alias, static_arr_ptrs_to_dbl, size_ptr);
for(i=0; i<SIZE; i++)
printf("Element %d is %lf", returned_pointer[i]);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.