Unit 2 - Practice Quiz

CSE109 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. Condition only
B. Increment/Decrement only
C. Initialization 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 breaks the switch loop.
D. It checks for errors.

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

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

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

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

15 What is the output of the following?
int i = 0; while(i < 3) { printf("%d ", i); i++; }

A. 1 2
B. 0 1 2
C. 1 2 3
D. 0 1 2 3

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

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

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

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

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

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

19 Implicit type conversion is also known as:

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

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. Error
B. d
C. Garbage value
D. %d

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

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

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

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

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

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

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

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

26 Which of the following best describes structured programming?

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

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

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

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

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

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

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

30 What is the result of 3 << 2?

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

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

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

32 The return statement is used to:

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

33 What is the correct syntax for a ternary operator?

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

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. while
B. do-while
C. repeat-until
D. for

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

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

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 can jump between different functions
B. It makes code easier to debug
C. It is required for loops
D. It is considered bad practice in structured programming

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. 11
B. Error
C. 10
D. Undefined

41 Which escape sequence represents a tab space?

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

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

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

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

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

44 Which function allows reading a string with spaces?

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

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

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

46 Short-circuit evaluation means:

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

47 Which data type is the result of sizeof operator?

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

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

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

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

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

50 The exit() function is used to:

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