Quiz 10
Quiz 10
Name: ______________________________________
MAbdullah Roll No: _____________________________
133715
Question 1: [2x8 marks] [est. time 8 minutes] d) (T / F) If there are more initializers in an array
Supply the missing words to complete the statements. initializer list than there are array elements: for
arrays.
1. Lists and tables of values are stored in ___________. example, int n[3] = {32, 27, 64, 18}; extra elements
2. What is the right way to initialize an array? will be ignored.
a. int num[6] = { 2, 4, 12, 5, 45, 5 }; e) (T / F) Recall that all arguments in C are passed
b. int n {} = { 2, 4, 12, 5, 45, 5 }; by value, so C automatically passes arrays to
c. int n{6} = { 2, 4, 12 };
d. int n(6) = { 2, 4, 12, 5, 45, 5 }; functions by value.
3. The number used to refer to a particular array element f) (T / F) Reading from out-of-bounds array
is called its ______________.
index.
elements can cause a program to crash or even appear
constant variable to execute correctly while using bad data.
4. A(n) _______ should be used to specify the size of an
array because it makes the program more modifiable. g) (T / F) An array subscript can be of data type
5. An array that uses two subscripts is referred to as a(n) double.
____________ array.
two-dimensional
Question 3: [3x3 marks] [estimated time 6 minutes]
7. What is the maximum number of dimensions an array Dry Run the pseudocode and write the expected
in C may have? output against the input. (Write “Blank” for no output
a. 2 or write “Compilation Error” if there is any error).
b. 6
c. 9 1.
d. No limit #include<stdio.h>
8. What will be the address of the arr [2][3] if arr is a 2- int main ()
{
Dimensioanl long array of 4 rows and 5 columns and the float arr [] = {12.4, 2.3, 4.5, 6.7};
starting address of the array is 2000? ______________. printf ("%d\n", sizeof(arr) / sizeof (arr [0]) );
2104
return 0;
}
Question 2: [1x7 marks] [est. time 7 minutes]
In the following questions mark True or False. Output: ______________________________________
4
a) (T / F) An array of type string can store a 2.
character string. // The array begins at address 1200 in memory.
b) (T / F) The following definition reserves space
#include<stdio.h>
for the double array temperatures, which have index int main ()
{
numbers in the range 0–6: int arr [] = {2, 3, 4, 1, 6};
double temperatures [7]; printf ("%u, %u, %u\n", arr, &arr [0], &arr);
return 0;
c) (T / F) For an int array, if you provide fewer }
initializers than there are elements in the array, the
Output: ______________________________________
1200, 1200, 1200
remaining elements are initialized to 0.
3. _____________________________________________
int n = 5, i, j, tmp;
int arr[n]= {1,6,3,2,8}; _____________________________________________
for (i=0; i<n; i++)
{ _____________________________________________
For (j=i+1; j<n; j++)
{ _____________________________________________
if(arr1[i] < arr1[j])
{ _____________________________________________
tmp = arr1[i];
arr1[i] = arr1[j]; _____________________________________________
arr1[j] = tmp;
}
_____________________________________________
}
}
The content of the array after running this program. _____________________________________________
Compolation Error
Output: ______________________________________ _____________________________________________