Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer the following questions about the program below: 1. Are arrays initialize

ID: 3813344 • Letter: A

Question

Answer the following questions about the program below:

1. Are arrays initialized by default? If not is there a notational shortcut?

2. Why does the last element of ratio print as 1.#INF00

3. What does 1.#INF00 mean?

#include <stdio.h>

#define SIZE 10

int main()

{

int i, j = 0;

int a[SIZE];

int b[SIZE] = {0};

double ratio[SIZE] = {0.0};

   for (i = 0; i < SIZE; i++){

a[i] = i;}

   for (i= 0, j = SIZE-1; i <SIZE; i++, j--){

b[j] = a[i];}

   for (i= 0; i < SIZE; i++){

ratio[i] = a[i]/ (double) b[i];}

  

   for (i= 0; i < SIZE; i++){

printf("ratio[%d]=%f ", i, ratio[i] );

   }

}

Explanation / Answer

1. Are arrays initialized by default? If not is there a notational shortcut?

Golbal arrays are automatically initialised to 0.

For local array they are no initialised by default, but can be done using shortcut similar to what is being used in code.

double ratio[SIZE] = {0.0};

otherway to initialise your array is using memset

2. Why does the last element of ratio print as 1.#INF00

Last element is 9/0.0. Now as denominator is 0 but as floating point arithmetic store number as approximation, it is not exactly 0. And dividing by a number infintely close to zero will lead to a very big number which is what 1.#INF00 represent.

3. What does 1.#INF00 mean?

It means positive infinity.

Please rate positively if this answer your query. Please comment if something is not clear.