Multiple Choice (some have more than one correct answer) (1 point each- 18 point
ID: 3707457 • Letter: M
Question
Multiple Choice (some have more than one correct answer) (1 point each- 18 points) a. arrayl1] array[8] 0 c. arayarray (8] 0 Exam 2 21.If an aray is declared with 8 memory locations, how would you set the first and last elements to zero? b. arrayto - array 7) d. None of the above 22. Which one is not a loop structure? a. do (]while(); b. if ) c. for()t) d. None of the above 23. Which of the following is TRUE? a. A single one-dimensional array can store multiple types b. Array values should always be of type double c. It is a syntax error if an array is assigned more values in a for) loop than there are elements d. The compiler can determine whether the program is going out of bounds of the original array declaration 24. Which of the following contains a syntax error? a. #include stdio.h b. int at3 2, 4, 6, 8 c. for (j 0 jExplanation / Answer
/**** Answering starting 5 questions ****/
21.) Array is declared with 8 memory locations. So there are total 8 locations indexing from 0 to 7. So first and last element can be set to zero by array[0] = array[7] = 0
22)answer will be if(){}. Because this is not a loop structure. "If" just checks the condtion, if it evaluated to true then it enters in the if block only once and never repeats. So its not a loop condition.
do{}while(); and for (; ; ){} these are the loop conditions
23.) For question 3 none of the statement is true because
a.) a single dimensional array can store value of same types not of different type. Because arrays are stored in contiguaous block of memory which can hold the same data type.
b.) Array can store values of any data type whether be int, float, char, double etc.
c.) In for loop if we are storing the more values than the elements it will not be synatx error. The compiler can not report it .Only at the run time you will get the exception.
d.) Compiler can never tell whether array is going out of bounds , it can be known at the run time only when the program throws the exception when the array goes out of index bound.
24.) Answer will be (a) you can not declare as #include stdio.h it should be #include<stdio.h>
b.) will not have synax error because you can declare a[3] = {2,4,6,8}. It is correct for multi dimensional array.
c.) and d.) also doesn't have any comilation error.
25.) (b), (c), (d) are correct.
(a). It is not necessary to declare and intiialize the variable at the begining of the main function. It can be declared and assigned at any place in the function.
b) Yes array can be declared with out knowing compiler that how many elements are there by using pointers. For example int *arr = NULL; here arr is an array without knowing that howmany elements are there.
c.) True . an expression conatining && is true if both the conditions are true.
d.) A switch case can be applied only for int, char and enum type for exact comparision
26.) In switch case it required to have default and break statements. See it is not mandatory to have default and break statements but it is required so that you don't end up in un wanted execution of code and it becomes hard to debug the code. If you don't add the default then if anything occurs other that the switch cases the termination occurs from end of switch case rather than the default break statement. If you don't have break statement then after executing first case it might enter to second case or third case to default.
An expression containing || operator is true even any of the condition is true.
option d is wrong because there are many decision statements in the C other than the swith like if, else etc.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.