NEW
Font size
WorksheetsCODE 4 KITSW ROUND - 2
Total questions: 25
Worksheet time: 8mins
What is the output of the following code snippet?
int x = 10, y = 20;
x > y ? printf("X") : printf("Y");
A) 10
B) 20
C) Compilation error
D) Y
Which statement is used to exit a loop prematurely in C?
A) exit
B) break
C) continue
D) return
How many types of decision-making statements are there in C?
A) 2
B) 3
C) 4
D) 5
What is the output of the following code snippet?
int x = 5;
if (x > 5)
printf("A");
else if (x < 5)
printf("B");
else
printf("C");
A) A
B) B
C) C
D) No output
What is the output of the following code snippet?
int main() {
int x = 5;
while (x > 0) {
printf("%d ", x--);}
return 0; }
54321
12345
55555
4321
What is the output of the following code snippet?
int main() {
int i;
for (i = 0; i < 5; i++) {
if (i == 2)
continue;
printf("%d ", i);
}
return 0;
}
0123
01234
0134
1234
Which statement is used to terminate the program in C?
A) exit
B) break
C) terminate
D) return
Which loop structure allows the code block to be executed at least once in C?
A) while loop
B) for loop
C) do-while loop
D) switch statement
In a nested if-else statement, how many else statements can follow an if statement?
A) 1
B) 2
C) 3
D) Unlimited
Which of the following loop condition is used to calculate the sum of all even numbers between 1 and 50.
A) for (int i = 1; i <= 50; i++)
B) for (int i = 2; i <= 50; i += 2)
C) for (int i = 0; i <= 50; i += 2)
D) for (int i = 2; i < 50; i += 2)
Which loop structure is best suited for situations where the number of iterations is known in advance in C?
A) while loop
B) for loop
C) do-while loop
D) switch statement
What is the purpose of the continue statement in C?
A) To exit a loop prematurely
B) To skip the current iteration of a loop
C) To restart the loop from the beginning
D) To jump to a specified line of code
How is memory allocated for one-dimensional arrays in C?
A) Dynamically at runtime
B) Statically at compile time
C) Automatically by the compiler
D) By using malloc function
What is the purpose of the return statement in C?
A) To exit the loop.
B) To skip the current iteration of a loop
C) To jump to a specified line of code
D) To terminate the program
How is a one-dimensional array declared in C?
A) int array[];
B) array[] int;
C) array int[];
D) int[] array;
Which operator is used for shortening simple if-else statements?
A) &
B) |
C) ?
D) :
What is the purpose of the goto statement in C?
A) To jump to a specified line of code
B) To exit a loop
C) To skip the current iteration of a loop
D) To call a function
Which operator is used for conditional assignment in C?
A) ==
B) =
C) ?
D) :
What will be the output of the following C code snippet?
int x = 5;
int y = 10;
x = x + y;
y = x - y;
x = x - y;
printf("x = %d, y = %d", x, y);
A) x = 5, y = 10
B) x = 10, y = 5
C) x = 0, y = 10
D) x = 10, y = 0
What is the output of the following code snippet
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", arr[2][1]);
4
5
7
8
What will be the output of the following code snippet?
int arr[] = {3, 6, 9, 12, 15}
int sum = 0;
for (int i=0; i<5;i++) {
sum += arr[i];
if (sum > 20)
break;
}
print("Sum: %d", sum);
Sum: 15
Sum: 18
Sum: 30
Sum:24
Suppose you have an array arr with elements {5, 9, 2, 7, 3} and you perform a linear search to find the element 7. Which of the following statements is true regarding the search algorithm?
The linear search algorithm will find the element 7 after examining all elements in the array.
The linear search algorithm will find the element 7 after examining the first three elements in the array.
The linear search algorithm will find the element 7 after examining the first four elements in the array.
The linear search algorithm cannot find the element 7 in the array.
What will be the output of the following code snippet?
int main() {
int x = 5;
int y = (x > 5) ? 10 : 20;
printf("y = %d", y);
return 0;
}
y = 10
y = 20
Compilation error
Undefined behavior
How are two-dimensional arrays accessed in C?
Using pointers only
Using row and column indices
Using nested loops to iterate over elements
Using arithmetic operations on indices
What will be the output of the following C code snippet?
int main() {
int x = 5;
int y = ++x;
printf("x = %d, y = %d", x, y);
return 0;
}
x = 5, y = 5
x = 6, y = 5
x = 5, y = 6
x = 6, y = 6
