CIE-2 Study Material
CIE-2 Study Material
Arrays
Array in C is one of the most used data structures in C programming. Arrays are used to store
multiple values in a single variable, instead of declaring separate variables for each value.
Array Declaration
In C, we have to declare the array like any other variable before using it. We can declare an array
by specifying its name, the type of its elements, and the size of its dimensions. When we declare
an array in C, the compiler allocates the memory block of the specified size to the array name.
Syntax:
data_type arrayname[size]; or data_type arrayname [size1][size2]….[sizeN];
We can access any element of an array in C using the array subscript operator [ ] and the index
value i of the element.
Array_name[index]
MCQ
Pseudocodes on Arrays:
1. What is the right way to initialize an array?
a. int num[6] = { 2, 4, 12, 5, 45, 5 }; c. int n{} = { 2, 4, 12, 5, 45, 5 };
b. int n{6} = { 2, 4, 12 }; d. int n(6) = { 2, 4, 12, 5, 45, 5 };
2. What will be the output of the program ?
#include <stdio.h>
void main()
{
int a[5] = { 5,1,15, 20,25},i,j,m;
i = ++a[1];
j = a[1]++;
m= a[i++];
printf(“%d%d%d”, i, j ,m);
}
a. 3,2,15 b. 2,3, 20 c. 2,1,15 d. 1,2,5
3. What will be the output of the program ?
#include <stdio.h>
void main()
{
char p;
3
int a[10];
printf(“%d%d”,a[-1],a[12]);
}
a. 0 0 b. Garbage value 0 c. 0 Garbagevalue d. GarbageValue
GarbageValue
11. What will be the output of the program if the array begins at address 65486?
#include<stdio.h>
void main()
{
int a[] = {12,14,15,23, 45}
printf(“%u%u”, a, &a);
}
a. 65486, 65488 b. 65486, 65490 c. 65486, 65487 d. 65486, 65486
12. What will be the output of the program?
#include<stdio.h>
void main()
{
float a[] = {12.4,2.3,4.5,6.7}
printf(“%d”, sizeof(a)/sizeof(a[0]));
}
a. 5 b. 4 c. 6 d. 7 e. None of these
13. Which of the following is the correct syntax to access the 3rd element of an array arr?
a. arr[2] b. arr(3) c. arr.2 d. arr{3}
14. In C, arrays are _ indexed.
a. 1 b. 2 c. 0 d. Negative
15. What does the following code print?
#include <stdio.h>
int main()
{
int arr[3] = {5, 10, 15};
printf("%d", arr[1]);
}
a. 5 b. 10 c. 15 d. Error
17. What will happen if you try to access an array element out of bounds?
a. The program will crash.
b. The compiler will catch the error.
c. The program will return garbage values.
d. The program will display a warning at runtime
18. What is the size of arr in the following code if int arr[10]; assuming int is 4 bytes?
a. 10 bytes b. 40 bytes c. 10 d. 4 bytes
19. What is the index of the last element in an array of size n in C?
a. n b. n-1 c. n+1 d. 0
20. What are the elements present in the array of the following int array[5] = {5};
a. 5, 5, 5, 5, 5 c. 5, (garbage), (garbage), (garbage), (garbage)
b. 5, 0, 0, 0, 0 d. (garbage), (garbage), (garbage), (garbage), 5
21. If integer requires 2bytes space, then what will be the size of the array int array[3][4]=(0);
a. 24 bytes b. 12 bytes c. 7 bytes d. 14 bytes
22. Consider the following declaration of an array int A[6] = {1,2,3,5}. Which of the
following statement is true?
a. Both A[2] and 2[A] represent the value 2
b. Both A[2] and 2[A] represent the value 3
c. A[2] is the correct way to access an element of A, but 2[A] will give an error.
d. The last two elements of the array A are 3 and 5
23. Consider the following array declaration:
int array1[]={2,3};
int array2[3]={9}
What will be the output of the following print statement?
printf(“%d%d”, array1[1],2[array2]);
a. 2,0 b. 3 0 c. 2 9 d. 3 9
24. What purpose does the following code serves
int main()
{
int array[] = {5, 3, 1, 9, 8, 2, 4, 7};
int size = sizeof(array)/sizeof(array[0]);
int i, j, min_idx,temp;
for (i = 0; i < size-1; i++)
{
min_idx = i;
for (j = i+1; j < size; j++)
{
if (array[j] < array[min_idx])
min_idx = j;
6
}
temp = array[min_idx];
array[min_idx] = array[i];
array[i] = temp; }
}
a. Finds some specific elements in the array c. Sort the elements of an
array
b. Find the smallest element in the array d. None of the above
25. What will be output of the following program
int main()
{
int arr[4]={3,4,5,6};
int k[4];
k=arr;
printf(“%d\n”,k[1]);
}
String functions:
MCQ
1. What is string in c language?
a. String is a new Data Type in C
8
#include<stdio.h>
void main()
{
printf(5+”Good Morning”);
}
a. Good Morning b. M c. Good d. Morning e. None of these
9. What will be the output of the program?
#include<stdio.h>
void main()
{
char str[]=”Exam\0Veda”;
printf(”%s”, str);
}
a. Exam b. Exam Veda c. Exam\0Veda d. Vedae. None of
these
10. The library function used to find the last occurrence of a character in a string is
a. strrchr() b. strstr() c. strnstr() d. laststr()
11. What is the output of the following code?
int main()
{
int str [] = {‘g’,’l’,’o’,’b’,’e’};
printf(“A%c”, str);
printf(“A%s”, str);
printf(“A%c”, str[0]);
return 0;
}
a. AAA b. A Ag Ag c. A*randomchar* Ag Ag d. compile
error
12. What is the output of the following code?
int main()
{
char str1[] = “JOHN”;
char str2[20] ;
str2=str1;
printf(“%s”, str2);
return 0;
}
a. JOHN b. J c. JOHN\0 d. Compile Error
13. What is the output of the code?
10
A. 96 days
B. 144 days
C. 120 days
D. 80 days
Q1.2: Ajay and Vijay together can complete a job in 40 days, while Ajay alone can finish it in 60 days.
How many days will Vijay take to do the job alone?
A. 120 days
B. 100 days
C. 80 days
D. 90 days
Q2.1: Rohit and Sohan can complete a work in 10 and 15 days, respectively. They work together for 5
days, and then Rohit leaves. How many more days will Sohan take to complete the remaining work?
A. 2 days
B. 3 days
C. 2.5 days
D. 5 days
Q2.2: Raj and Simran can finish a task in 8 and 12 days, respectively. They work together for 4 days, and
then Raj leaves. How many more days will Simran need to finish the remaining task?
A. 2 days
B. 3 days
C. 1.5 days
D. 2.5 days
Answer: A. 2 days
Q3.1: 6 men or 9 women can finish a job in 12 days. How many men must work with 18 women to
complete the job in 4 days?
A. 5 men
B. 6 men
C. 8 men
D. 7 men
Answer: B 6 men
12
Q3.2: 3 men or 6 women can finish a task in 10 days. How many men should work with 12 women to
complete the work in 3 days?
A. 4 men
B. 3 men
C. 2 men
D. 5 men
Answer: A. 4 men
Q4.1: 30 men can complete a task in 24 days. After 9 days, 20 more men join them. How many more
days will it take to finish the work?
A. 12 days
B. 10 days
C. 14 days
D. 9 days
Answer: D. 9 days
Q4.2: 60 workers can complete a job in 20 days. After 5 days, 40 additional workers join them. How many
days will it take to complete the remaining work?
A. 10 days
B. 8 days
C. 9 days
D. 7 days
Answer: C. 9 days
Q5.1: How many 3-digit odd numbers (with distinct digits) can you form using 0, 2, 3, 4, 5, 6?
A. 48
B. 60
C. 72
D. 32
Answer: D. 32
Q5.2: How many 4-digit even numbers (with distinct digits) can be formed using 1, 2, 3, 4, 5, 6?
13
A. 120
B. 180
C. 168
D. 192
Answer: B. 180
Q6.1: How many 6-letter words can be formed using the letters in "BANANA" if each letter can be used
only once?
A. 60
B. 420
C. 210
D. 120
Answer: A. 60
Q6.2: How many 7-letter words can be formed using the letters in "BALLOON" if each letter can be used
only once?
A. 420
B. 840
C. 5040
D. 1260
Answer: D. 1260
Q7.1: 8 people are to sit in a row. In how many ways can this be done if 3 specific people always sit
together?
A. 120,960
B. 720
C. 4320
D. 60,480
Answer: C. 4320
Q7.2: 5 men and 4 women are to sit in a row. In how many ways can they be seated if all women must sit
together?
14
A. 17,280
B. 2,880
C. 362880
D. 12,960
Answer: A. 17280
Q8.1: The mean of 40 observations was 55. Later, it was found that an observation 75 was wrongly
recorded as 25. What is the correct mean?
A. 56.25
B. 55.75
C. 55.50
D. 56.00
Answer: A. 56.25
Q8.2: The mean of 25 observations was 64. It was later discovered that an observation recorded as 50
should have been 80. What is the corrected mean?
A. 65.2
B. 64.8
C. 66.0
D. 65.6
Answer: A. 65.2
Q9.1: A batsman has an average of 50 runs after 6 innings. After his seventh inning, the average
decreases to 48. How many runs did he score in the seventh inning?
A. 30
B. 36
C. 40
D. 44
Answer: B. 36
Q9.2: A cricketer has an average of 42 runs after 8 innings. In the ninth inning, his average drops to 40.
How many runs did he score in the ninth inning?
15
A. 24
B. 28
C. 30
D. 32
Answer: A. 24
Q10.1: The average age of 30 people is 40 years. 10 new people join, and their average age is 35 years.
What is the average age of the group now?
A. 38.75
B. 39.0
C. 39.5
D. 40.5
Answer: A. 38.75
Q10.2: The average age of a group of 20 people is 25 years. If 5 new members with an average age of 30
years join, what is the average age of the new group?
A. 27
B. 26
C. 28
D. 29
Answer: B. 26
Q11.1: Two sugar solutions, A (30%) and B (50%), are mixed in the ratio 3:2. What is the concentration of
the resulting solution?
A. 38%
B. 40%
C. 42%
D. 45%
Answer: A. 38%
Q11.2: Two mixtures of alcohol and water have concentrations of 70% and 40%, respectively. If they are
mixed in the ratio 1:2, what is the concentration of alcohol in the final mixture?
16
A. 45%
B. 55%
C. 60%
D. 50%
Answer: D. 50%
Q12.1: A 40-liter solution contains 8% sugar. Another solution with 4% sugar is added. How many liters
of the second solution should be added to make the mixture 5% sugar?
A. 40 liters
B. 50 liters
C. 120 liters
D. 80 liters
Q12.2: A 60-liter solution has 10% alcohol. Another solution with 5% alcohol is added. How many liters
of the second solution should be added to create a mixture with 8% alcohol?
A. 30 liters
B. 40 liters
C. 50 liters
D. 60 liters
Answer: B. 40 liters
Q13.1: Milk and water are in the ratio 3:2 in one container and 5:4 in another. In what ratio should they
be mixed to get a mixture containing 7:6 milk and water?
A. 2:3
B. 3:4
C. 4:5
D. 5:18
Answer: D. 5:18
Q13.2: Two containers have milk and water in the ratios 7:5 and 3:2, respectively. In what ratio should
these mixtures be combined to get a final mixture with milk and water in the ratio 5:4?
17
A. 4:3
B. 3:2
C. 5:4
D. 8:5
Answer: D. 8:5