/* * SelfTest1 * Chapter 10 * By John Stile */ 1) What line declares and initializes an array of three integers with values of: 17, 36, and 22? ANSWER: int aa[4]={17,36,22}; 2) What printf line outputs the 36 in the valiable initialized in question 1? ANSWER: printf("%d\n", aa[1] ); 3) Consider the following code fragment: { int ii, sum = 0; for (ii=0; ii<15; ii++) { printf("Test score %d: %d\n", ii, scores[ii]); sum += scores[ii]; } } 3a) How many times will the loop execute and why? ANSWER: 15 times 3b) How does printf work? ANSWER: prints decimal value of ii and scores[ii] 4. In a char array that holds 15 elements, a user enters a name that only 7 characters long. Why does printf output only 7 charactes of the name? ANSWER: A NULL character is inserted into the remaining slots of the array, and printf quits after reaching NULL character. 5) Consider: char fname[20]={"William"}; 5a) What printf line outputs only the a in William? ANSWER: printf("%c",fname[5]); 5b) What printf line outputs the whole array? ANSWER: printf("%s",fname); 6) Consider scanf("%s", abc); 6a) What does this line accomplish/ ANSWER: reads in a string and stores in array abc 6b) What would the variable declaration line look like? ANSWER: char abc[10];