0% found this document useful (0 votes)
16 views

c Program Unit 2

Vtvv

Uploaded by

bobyc1810
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

c Program Unit 2

Vtvv

Uploaded by

bobyc1810
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. What is the correct syntax for an if statement in C?

A) if a == b

B) if (a == b)

C) if {a == b}

D) if a = b

Answer: B) if (a == b)

2. Which of the following is an example of a conditional statement?

A) for

B) while

C) if-else

D) do-while

Answer: C) if-else

3. What type of loop structure always executes its block of code at least once?

A) for loop

B) while loop

C) do-while loop

D) if-else

Answer: C) do-while loop

4. What will the following code print?int i = 0;

while (i < 3) {

printf("%d ", i);

i++;

A) 0 1 2

B) 1 2 3

C) 0 1 2 3

D) 1 2

Answer: A) 0 1 2

5. In C, how do you declare a single-dimensional array of integers with size 10?

A) int array[10];

B) array int[10];

C) int array();

D) array[10];

Answer: A) int array[10];


6. Which statement will skip the current iteration of a loop and continue with the next iteration?

A) break

B) return

C) continue

D) exit

Answer: C) continue

7. In nested if statements, how does the control flow work?

A) The last if statement is executed first

B) Each if is checked independently

C) Inner if is checked only if the outer if is true

D) None of the above

Answer: C) Inner if is checked only if the outer if is true

8. What is the purpose of the switch statement in C?

A) To execute one block of code out of many possible blocks based on a value

B) To loop through code a certain number of times

C) To handle exceptions

D) None of the above

Answer: A) To execute one block of code out of many possible blocks based on a value

9. Which keyword is used to break out of a loop prematurely?

A) exit

B) continue

C) break

D) stop

Answer: C) break

10. How do you declare a 2D array in C?

A) int array[][];

B) int array[10][10];

C) int array(10)(10);

D) array[10,10];

Answer: B) int array[10][10]

11. Which of the following is not an iterative statement?

A) for

Loop

B) while loop
C) if-else

D) do-while loop

Answer: C) if-else

12. Which of the following is the correct syntax for a for loop in C?

A) for (initialization; condition; increment/decrement)

B) for (initialization, increment/decrement, condition)

C) for (condition; initialization; increment/decrement)

D) for initialization; increment/decrement; condition

Answer: A) for (initialization; condition; increment/decrement

)13. Which loop will always execute the loop body at least once, even if the condition is false?

A) for

B) while

C) do-while

D) None of the above

Answer: C) do-while

14. What is the output of the following code?int i = 0;

do {

printf("%d ", i);

i++;

} while (i < 3);

A) 0 1 2

B) 0 1 2 3

C) 1 2 3

D) 1 2

Answer: A) 0 1 2

15. Which of the following data structures is used to declare arrays in C?

A) Stack

B) Queue

C) List

D) Contiguous memory locations

Answer: D) Contiguous memory locations

16. What is the correct way to declare a single-dimensional integer array of 5 elements in C?

A) int arr[];

B) int arr[5];
C) int arr(5);

D) int arr;

Answer: B) int arr[5];

17. Which statement is used to terminate a loop or a switch-case statement prematurely?

A) continue

B) return

C) break

D) exit

Answer: C) break

18. What is the output of the following code?int i = 10;

if (i == 10) {

printf("Ten");

} else {

printf("Not Ten");

A) Ten

B) Not Ten

C) 10

D) Error

Answer: A) Ten

19. In a switch statement, which keyword is used to skip to the next case after executing a case block?

A) continue

B) break

C) goto

D) exit

Answer: B) break

20. What is the default case in a switch statement used for?

A) It is required and must always be written

B) It executes if no matching case is found

C) It exits the loop

D) It resets the value of the switch variable

Answer: B) It executes if no matching case is found

21. Which of the following operators is used to access elements in an array in C?

A) .
B) ->

C) []

D) {}

Answer: C) []

22. Which of the following types of loops is best for when the number of iterations is known?

A) while

B) do-while

C) for

D) if-else

Answer: C) for

23. In a while loop when is the codition checked?

A) before each iteration

B) after each iteration

C) only once at the beginning

D) after the loop body executes

Answer:A) before each iteration

24.Which of the following is true about nested if statements?

A) they allow multiple conditions to be checked in sequence

B) only the outermost if is executed

C) they can not contain else statements

D) they execute independently of each other

Answer:A) they allow multiple conditions to be checked in sequence

25. what is the correct way to declare a two dimensional array in C?

A) int arr[2,3];

B) int arr [2][3];

C) int arr[2] 3;

D) int arr{2}{3};

Answer:b) int arr[2][3];

26.In a switch case statement what will happen if break is omitted form a case?

A) the program will exit the switch statement

B) the program will execute all the subsequent cases

C) the program will generate a compilation error

D) only the current case will be executed.

Answer: B) the program will execute all the subsequent cases.


27. the condtion in a while loop is checked.

A) after executing the loop body

B) before executing the loop body

C) randomly during the execution

D) none of the above

Answer: B) before executing the loop body

28. An array in C is used for:

A) store a collection of variables of different data types

B) store a collection of variables pf the same data type

C) store a fixed number of variables with dynamic size

D) store a variable number of elements without of the same data type

Answer: B) store a collection of variables pf the same data type

29.which of the following loop is guranated to execute at least once?

A) for loop

B) while loop

C) do while loop

D) none of the above

Answer:C) do while loop

30. which of the following is used to make a decision in a C program?

A) loop

B) if else statement

C) switch case statement

D) both b and c

Answer: D0 both b and c

31.in the for loop how many times is the condition checked?

A) only once

B) once at the beginning of the loop

C) once before every iteration

D) only after every iteration

Answer: C)

31.which statement is used to skip the remaining statements in the current iteration of a loop and proceed with the
next iteration?

A) break

B)continue
C)return

D)go to

Answer: B) continue

32.how can you exit frona an infinite loop?

A)using the continue statement

B) using the break statement

C) by using a conditional statement inside the loop

D) using both b abd c

Answer:D)using both b and c

33. what happens when the break statement is udes in a nested loop?

A) it exits only the innermost loop

B)it exits all loops

C) it exits the outer loop

D) it causes an infinite loop

Answer: A) it exits only the innermost loop

34.In a for loop,which part is responsible for updating the loop counter?

A) initialization

B)condtion

C)increment/decrement

D) none of the above

Answer: C) increment/decrement

You might also like