0% found this document useful (0 votes)
13 views2 pages

Quiz 10

The document is a quiz for a Programming Fundamentals course focused on arrays, covering topics such as array initialization, indexing, and memory addresses. It includes multiple-choice questions, true/false statements, and programming exercises related to arrays. The quiz assesses students' understanding of array concepts and their ability to write C programs involving arrays.

Uploaded by

mabdullah4505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Quiz 10

The document is a quiz for a Programming Fundamentals course focused on arrays, covering topics such as array initialization, indexing, and memory addresses. It includes multiple-choice questions, true/false statements, and programming exercises related to arrays. The quiz assesses students' understanding of array concepts and their ability to write C programs involving arrays.

Uploaded by

mabdullah4505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CC-112 Programming Fundamentals Spring 2022

Quiz 10 – Lecture 12-13-14 – Arrays – I-II-III [40 Marks, 30 Minutes]

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.

Quiz 09 – Lecture 09-10-11 – Modular Programming – II-III-IV Page 1 of 2


CC-112 Programming Fundamentals Spring 2022

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: ______________________________________ _____________________________________________

Question 4: [8 marks] [estimated time 9 minutes] _____________________________________________


Write a C program that:
 Take input of an array of size 10 from the user. _____________________________________________
 Count total number of duplicate elements in an
array _____________________________________________
 Output the count of duplicate elements in the
array. _____________________________________________
For an array arr [10] = {2,2,4,5,6,7,3,3,7,9}
_____________________________________________
Expected Output: 3
_____________________________________________
#include <stdio.h> _____________________________________________

int countDuplicates(int arr[], int size) {


_____________________________________________ _____________________________________________
int count = 0;
for (int i = 0; i < size; i++) {
_____________________________________________
for (int j = i + 1; j < size; j++) {
_____________________________________________
if (arr[i] == arr[j]) {
_____________________________________________
count++; _____________________________________________
break; // Prevent duplicate counting
}
_____________________________________________ _____________________________________________
}
}
_____________________________________________ _____________________________________________
return count;
}
_____________________________________________ _____________________________________________
int main() {
_____________________________________________
int arr[10]; _____________________________________________
printf("Enter 10 elements:\n");
for (int i = 0; i < 10; i++) {
_____________________________________________ _____________________________________________
scanf("%d", &arr[i]);
}
_____________________________________________ _____________________________________________
printf("Total duplicate elements: %d\n", countDuplicates(arr, 10));
_____________________________________________
return 0; _____________________________________________
}

Quiz 10 – Lecture 12-13-14 – Arrays – I-II-III Page 2 of 2

You might also like