Question Bank UNIT III
Question Bank UNIT III
Part A
1. What is an array?
An array is a group of similar data types stored under a common name. An array is used to
store a collection of data, but it is often more useful to think of an array as a collection of
variables of the same type.
Example:
int a[10];
Here a[10] is an array with 10 values.
2. What are the main elements of an array declaration?
1. Array name
2. Type
3. Size
3. How to initialize an array?
You can initialize array in C either one by one or using a single statement as follows:
double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};
The number of values between braces { } cannot be larger than the number of
elements that we declare for the array between square brackets [ ]. Following is an example
to assign a single element of the array:
4. Why is it necessary to give the size of an array in an array declaration?
When an array is declared, the compiler allocates a base address and reserves enough
space in the memory for all the elements of the array. The size is required to allocate the
required space. Thus, the size must be mentioned.
#include <stdio.h>
int main() Output
{
int array[] = {15, 50, 34, 20, 10, 79, 100}; Size of the given array is 7
int n;
n = sizeof(array);
printf("Size of the given array is %d\n",n/sizeof(int));
return 0;
}
OUTPUT:
Size of the given array is 7
Array declaration, initialization and Int Array Example Character Array Example
Accessing
Array declaration syntax: Integer array example: char str[10];
data_type arr_name [arr_size]; int age [5];
Part B
1. Write in detail about the array in C with suitable example.
2. Write about the various operations applied on strings.
3. Write a program to arrange n names in ascending order.
4. What is a function. Describe in detail about the function with suitable example.
5. List and explain various function representations in C with suitable example.
6. Write a program to arrange the numbers in descending order.
7. Try the Hacker rank problem for your practice.
https://www.hackerrank.com/challenges/1d-arrays-in-c/problem
Create an array of size dynamically, and read the values from stdin. Iterate the
array calculating the sum of all elements. Print the sum and free the memory
where the array is stored. While it is true that you can sum the elements as they
are read, without first storing them to an array, but you will not get the experience
working with an array. Efficiency will be required later.
Input Format
The first line contains an integer,
The next line contains space-separated integers.
Sample Input 0
6
16 13 7 2 1 12
Sample Output 0
51
8. Create an array of size dynamically and read the values from stdin. Reverse the array and
print the result.
9. Two set of lists are given. The first list is an original one. The second one has numbers
where some numbers are missed out of the original list. Write a C program to find and
print the missing numbers of the second list?
For Example, the original list a = [12, 10, 4, 11, 16, 5, 21, 30] and the missing list,
b = [12, 4, 16, 5, 30], here, the missing numbers are 10, 11 and 21.
OUTPUT:
Enter a base number: 3 int base, exponent;
Enter an exponent: 4 long long result = 1;
Answer = 81