Statistic

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Part I: Multiple Choice Questions (2 points each)

1. Which of these best describes an array?

b. Container of objects of similar types

2. How do you initialize an array in C?

c. int arr[3] = {1,2,3};

3. What is the output of the following piece of code?

c. ArrayIndexOutOfBoundsException

4. Which of the following concepts make extensive use of arrays?

d. Spatial locality

5. What are the advantages of arrays?

d. Easier to store elements of same data type

Part II: Review Questions (3 points each)

1. Discuss about the pointer conversion.

- Pointer conversion is the process of changing the type of a pointer in a programming language.
There are two main types: implicit and explicit (type casting) conversions. Implicit conversions are
allowed when the target data type is less restrictive than the source data type. Explicit conversions
involve using a type cast to convert a pointer, and they should be done with caution as they can lead to
runtime errors or security vulnerabilities if not handled properly. In languages like C and C++, where
pointer conversions are common, it's essential for programmers to be aware of the potential risks and
to ensure that the conversions are valid.

2. What is pointer comparison?

- Pointer comparison is the process of comparing two pointers in a programming language to assess
whether they point to the same memory location, or to establish an order between them in memory.
This is vital for tasks like array operations and null pointer checks. It includes equality, inequality, and
relational comparisons. Care must be taken when comparing pointers to avoid undefined behavior, such
as null pointer dereferencing or out-of-bounds memory access. Pointer comparison is a fundamental
operation in languages like C and C++.

3. Describe the basic operations of array.

- Basic operations of arrays include declaration (defining size and data type), initialization (assigning
values to elements), access (retrieving elements by index), updating (changing element values), traversal
(looping through elements), insertion and deletion, search, sorting, concatenation, finding length,
copying, and cloning. These operations are fundamental for working with arrays in various programming
languages and are used for storing and manipulating collections of data elements.
4. How to find the largest and smallest number in unsorted array?

- To find the largest and smallest numbers in an unsorted array:

 Initialize variables to store the largest and smallest values, both set to the first element of the
array.
 Iterate through the array, starting from the second element.
 For each element, compare it with the current largest and smallest values, updating them as
needed.
 Continue this process for all elements in the array.
 After the loop, the variables will hold the largest and smallest values in the array.

5. How to find repeated numbers in an array if it contains multiple duplicates?

- To find repeated numbers in an array with multiple duplicates:

 Initialize an empty hash table (dictionary) to store counts of each number.


 Iterate through the array, counting the occurrences of each number in the hash table.
 After the array is processed, check the hash table for elements with counts greater than 1; these
are the repeated numbers.
 Optionally, store the repeated numbers in a separate array if needed.

Part III: Fill in the missing piece of code (5 points each)

// C Program to Insert an element

1. int arr

2. i = 0; i < n; i++

3. "%d ", arr[i]

4. ++;

5. pos

Prepared by:

LOILA S. EMPIMO

Faculty

You might also like