______ loops are especially useful when dealing with two-dimensional arrays beca
ID: 3848820 • Letter: #
Question
______ loops are especially useful when dealing with two-dimensional arrays because they allow the programmer to designate and cycle through each element easily. a) Nested b) Single c) Simple d)Conditional Which one of the following array initializations is incorrect? a) int x[4] = {8, 7, 6, 5, 4}: b) int x[] = {8, 7, 6, 5, 4}: c) int x[4] = {8, 7, 6}: d) const int SIZE = 4: When a function having an array as a parameter is called, the array parameter a) names a copy of the array argument. b) refers to exactly the same array as the calling program c) is passed the address of the argument, and the function needs further information about the array size to use an array parameter d) refers to the array using a name that is always different from the calling program's argument.Explanation / Answer
7. Nested Loops
Exmple of nested loop:
for( i = 0; i < 10; i = i++){
{
for( j = 0; j < 10; j = j++){
{
array[i][j] = i + j;
}
}
8. a) int x[4]= {1,2,3,4,5}; // error: too many initializers for ‘int [4]’
int x[] = {1,2,3}; // x has type int[3] and holds 1,2,3
int y[5] = {1,2,3}; // y has type int[5] and holds 1,2,3,0,0
int z[3] = {0}; // z has type int[3] and holds all zeroes
int array[define_asize] = {1,2,3,4,5,6,7,8,9,0}; // const int const_asize = 10;
9. C) is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter
When passing an array as a parameter to a function it is passed as a reference parameter. It is actually passed the address of its first element. Since arrays are passed by reference this means that if the function changes the value of an element in an array that is a parameter of the function then the corresponding actual array of the call will have that element changed. Though an array is passed as a reference parameter an ‘&’ is not used to denote a reference parameter. However it must be indicated to the compiler that this parameter is an array by appending [] to the formal parameter name. Thus to declare an array of real values as a parameter requires the parameter to be specified.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.