Unit 2 - Practice Quiz

CSE109

1 Which of the following is the correct syntax for a switch statement expression in C?

A. Must be a float or double
B. Must be an integer or character type
C. Can be any data type
D. Must be a string

2 What is the minimum number of times a do-while loop is guaranteed to execute?

A.
B. 1
C. Infinite
D. Variable based on condition

3 Which format specifier is used to read a single character in scanf()?

A. %s
B. %d
C. %c
D. %f

4 What is the output of the following C code fragment?

c
int a = 5;
if (a = 0) {
printf("True");
} else {
printf("False");
}

A. True
B. False
C. Compilation Error
D. Runtime Error

5 Which jump statement is used to immediately terminate the current iteration of a loop and proceed to the next iteration?

A. break
B. goto
C. return
D. continue

6 What does the break statement do when used inside a nested loop?

A. Exits all loops
B. Exits only the innermost loop
C. Exits the program
D. Restarts the loop

7 Which of the following is an example of an unformatted input function?

A. scanf()
B. printf()
C. gets()
D. fprintf()

8 What is the result of the expression (float)5 / 2?

A. 2
B. 2.5
C. 2.0
D. Error

9 Which keyword is used to transfer control to a specific label within the same function?

A. switch
B. jump
C. goto
D. move

10 What is the return type of the printf() function?

A. void
B. int
C. char *
D. float

11 In the syntax for(initialization; condition; increment/decrement), which part is optional?

A. Initialization only
B. Condition only
C. Increment/Decrement only
D. All parts are optional

12 What is the role of the default case in a switch statement?

A. It is mandatory and executes first.
B. It executes if no other case matches.
C. It checks for errors.
D. It breaks the switch loop.

13 Which type modifier allows a variable to store only positive integers?

A. short
B. long
C. signed
D. unsigned

14 What is the purpose of the & operator in scanf("%d", &a)?

A. Bitwise AND
B. Logical AND
C. Address of operator
D. Reference type

15 What is the output of the following?
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

16 Which of the following functions appends a newline character \n automatically at the end of the output?

A. printf()
B. puts()
C. putchar()
D. fprintf()

17 What happens if a break statement is omitted in a switch case?

A. Compiler Error
B. The program crashes
C. Fall-through occurs (subsequent cases execute)
D. The loop resets

18 Which format specifier is used to print a floating-point number in scientific notation?

A. %f
B. %d
C. %e
D. %g

19 Implicit type conversion is also known as:

A. Type Casting
B. Coercion
C. Dynamic typing
D. Static typing

20 Which logic structure fits the description: 'Execute a block of code repeatedly as long as a condition is true, checking the condition before execution'?

A. do-while
B. while
C. switch
D. if-else

21 What is the output of printf("%%d");?

A. %d
B. d
C. Garbage value
D. Error

22 Which of the following creates a block scope in C?

A. Square brackets []
B. Parentheses ()
C. Curly braces {}
D. Angle brackets <>

23 If x = 5, what is the value of x after x += x + 5?

A. 10
B. 15
C. 20
D. 25

24 Which header file is generally required for printf and scanf?

A. <conio.h>
B. <stdlib.h>
C. <stdio.h>
D. <string.h>

25 What happens if the condition in a while loop is initially false?

A. The loop executes once
B. The loop executes infinitely
C. The loop body is never executed
D. Runtime error

26 Which of the following best describes structured programming?

A. Using goto statements extensively
B. Writing all code in the main function
C. Using control structures like loops and conditionals to organize code logic
D. Declaring all variables as global

27 What is the size modifier to print a long double?

A. %f
B. %lf
C. %Lf
D. %ld

28 Which statement allows skipping the current pass in a loop but continuing with the next?

A. break
B. stop
C. continue
D. exit

29 In a switch statement, can two cases have the same value?

A. Yes, always
B. No, duplicate case values cause a compilation error
C. Yes, if they are in different blocks
D. Yes, if one is default

30 What is the result of 3 << 2?

A. 6
B. 12
C. 9
D. 5

31 Which function is unsafe to use because it does not check the buffer size?

A. fgets()
B. scanf() with width
C. gets()
D. getchar()

32 The return statement is used to:

A. Restart the program
B. Exit from a function and optionally return a value
C. Print a value
D. Exit a loop only

33 What is the correct syntax for a ternary operator?

A. condition ? expression1 : expression2
B. condition : expression1 ? expression2
C. condition ? expression1 ; expression2
D. expression1 ? expression2 : condition

34 In the format string "%5d", what does the 5 represent?

A. Precision
B. Maximum value
C. Minimum field width
D. Array size

35 Which of the following is NOT a looping structure in C?

A. for
B. while
C. repeat-until
D. do-while

36 What is the output of printf("%.2f", 3.14159);?

A. 3.14159
B. 3.14
C. 3.15
D. 3.1

37 When defining a variable long int, which keyword can be omitted?

A. long
B. int
C. long or int
D. Neither

38 Which of the following statements about goto is true?

A. It makes code easier to debug
B. It is considered bad practice in structured programming
C. It can jump between different functions
D. It is required for loops

39 What does putchar(c) do?

A. Reads a character c
B. Prints the integer value of c
C. Prints the character stored in variable c to stdout
D. Puts c into memory

40 If int a = 10;, what is the value of a after printf("%d", a++); executes?

A. 10
B. 11
C. Undefined
D. Error

41 Which escape sequence represents a tab space?

A. \s
B. \t
C. \b
D. \n

42 What happens if you assign a float value to an int variable?

A. Rounding to nearest integer
B. Truncation of the fractional part
C. Compilation error
D. Runtime error

43 In a for loop, when is the initialization expression executed?

A. Before every iteration
B. Only once at the start
C. After every iteration
D. When the loop terminates

44 Which function allows reading a string with spaces?

A. scanf("%s", str)
B. gets(str)
C. getchar()
D. getch()

45 What is the correct way to output a double quote character " using printf?

A. "
B. \"
C. %'
D. \q

46 Short-circuit evaluation means:

A. Evaluating all operands regardless of result
B. Stopping evaluation as soon as the result is determined
C. Skipping the loop body
D. Compiling code faster

47 Which data type is the result of sizeof operator?

A. int
B. long
C. size_t
D. float

48 What is the output of int x=1; switch(x) { case 1: printf("1"); case 2: printf("2"); }?

A. 1
B. 12
C. 2
D. Error

49 Which of the following is a valid variable declaration using a type modifier?

A. unsigned float x;
B. long char c;
C. short int i;
D. signed void v;

50 The exit() function is used to:

A. Exit a loop
B. Exit the current function
C. Terminate the program execution completely
D. Pause the program