Please answer the question 3 with the referrence of question 2. Thank you! 2. Wh
ID: 3745836 • Letter: P
Question
Please answer the question 3 with the referrence of question 2. Thank you!
2. When we want to intialize a dynamically allocated float array we may choose one of the following methods: The array size is not specified so it is intialized to 1 and the values stored in the array is set to 0.0 The array is allocated to a specified size but the values stored in the array are not specified. In this case, all the values in the array are set to 0.0. The array is allocated to a specified size and the values stored in the array are all set to a specified value. Write the three versions of the init) function in the following program:Explanation / Answer
float* init(){
return 0.0;
}
float* init(int n){
float *res = new float[n](0);
return res;
}
float* init(int n, int val){
float *res = new float[n];
for(int i=0;i<n;i++){
res[i]=0;
}
return res;
}