1. Which of the following is a valid C statement for creating and initializing a
ID: 3601965 • Letter: 1
Question
1. Which of the following is a valid C statement for creating and initializing an array of floating point values? a. double densities [ 4.0]: b. int densities [4] = { 1.5, 2.3, 0.1, 4.6 ); c. double densities [ ] = { 1.5, 2.3, 0.1, 4.6); d. int densities [ : e, double densities = { 1.5, 2.3, 0.1, 4.6 ); f. none of the above Which of the following is a valid C code for assigning the same value to each element in an array of floating point values named masses, with a length of 7? 2. a. int j for (j=0; jExplanation / Answer
1.
array of floating point values:
a. double densities[4.0];
it is not valid, because size should be number but it is decimal so it is not valid.
b. int densities[4]={1.5,2.3,0.1,4.6}
it is not valid, here data type holds integer not float type.
c. double densities[4]={1.5,2.3,0.1,4.6}
it is valid
d. int densities[];
not valid, data type holds int not float.
e. double densities={1.5,2.3,0.1,4.6}
not valid, here densities is a normal variable can't hold array values
2.
Assigning same float values to array mass length 7:
a. int j;
for(j=0;j<=7;j++)
{ masses[j]=2 }
not valid because j=0 to 7 size becomes 8 not 7.
b.
int j;
for(j=1;j<7;j++)
{ masses[j]=2 }
not valid because j=1 to 6 size becomes 6 not 7
c.
int j;
for(j=1;j<=7;j++)
{ masses=2 }
assigning to masses variable not to masses array variable.
d.
int j;
for(j=0;j<7;j++)
{ masses[j]=2 }
it is valid.
e.
double j;
for(j=0;j<7;j++)
{ masses[j]=2 }
it is not valid here j is floating type not integer, array index should be integer.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.