Unit 2 - Practice Quiz

CSE101

1 Which of the following statements is true regarding the execution of the if-else statement in C?

A. The else block is executed only when the if condition evaluates to 0.
B. The else block is executed only when the if condition evaluates to 1.
C. Both blocks are executed sequentially.
D. The else block is mandatory in every if statement.

2 What is the output of the following code snippet?

c
int a = 10;
if (a = 5)
printf("True");
else
printf("False");

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

3 Which data types are allowed for the expression in a switch statement in C?

A. int and char
B. int, char, and float
C. float and double
D. Any data type

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

A. The compiler generates an error.
B. Execution stops immediately.
C. Execution falls through to the next case.
D. The program enters an infinite loop.

5 Which of the following is an Exit Controlled Loop?

A. for loop
B. while loop
C. do-while loop
D. if-else statement

6 What is the minimum number of times a while loop is guaranteed to execute?

A.
B. 1
C. Infinite
D. Depends on the compiler

7 Consider the mathematical expression: . Which loop structure best represents this summation?

A. for(i=1; i<=10; i++) S = S + i;
B. for(i=1; i<10; i++) S = S + i;
C. while(i<=10) S = S + i; (without initialization)
D. do { S = S + i; } while(i < 10);

8 What is the purpose of the continue statement?

A. To terminate the program.
B. To exit the current loop immediately.
C. To skip the rest of the code in the current iteration and jump to the loop update/condition.
D. To restart the loop from the beginning variable initialization.

9 In the following nested loop, when does the break statement stop execution?
c
for(i=0; i<5; i++) {
for(j=0; j<5; j++) {
if(j==2) break;
}
}

A. It terminates both the inner and outer loops.
B. It terminates only the inner loop.
C. It terminates only the outer loop.
D. It terminates the program.

10 Which of the following is the correct syntax for a goto label?

A. label name:
B. label_name:
C. :label_name
D. label-name;

11 What does the return statement do in a function having a void return type?

A. It returns a value to the caller.
B. It is illegal to use return in void functions.
C. It immediately terminates the function execution and returns control to the caller.
D. It restarts the function.

12 Which formatting code is used to print a double value in scientific notation using printf?

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

13 What is the return value of the scanf() function?

A. The value read from input.
B. The number of characters read.
C. The number of items successfully read and assigned.
D. Standard boolean True/False.

14 Which function is best suited to read a string containing spaces (e.g., "Hello World") from standard input?

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

15 What does the printf field width specifier %5d imply when printing the integer 10?

A. It prints 10 followed by 3 spaces.
B. It prints 3 spaces followed by 10.
C. It prints 5 zeros followed by 10.
D. It prints 10 five times.

16 Which of the following is an example of Explicit Type Casting?

A. float a = 10;
B. int a = 5.5;
C. float a = (float)5 / 2;
D. long a = 100;

17 What is the result of the expression in C when variables are integers?

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

18 Which type modifier increases the range of values a variable can store by utilizing the sign bit?

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

19 In structured programming, breaking a large program into smaller, manageable sub-programs is known as:

A. Bottom-up design
B. Top-down design (Modularity)
C. Linear programming
D. Object-Oriented programming

20 What is the correct format specifier to read a single character using scanf?

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

21 What is the output of puts("Hello");?

A. Prints "Hello" and stays on the same line.
B. Prints "Hello" and moves the cursor to the next line.
C. Prints "Hello" enclosed in quotes.
D. Returns the ASCII value of 'H'.

22 Which escape sequence represents a horizontal tab?

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

23 In a for loop for(init; condition; update), if the condition is left blank, how is it interpreted?

A. It is treated as false (0).
B. It is treated as true (non-zero).
C. It causes a syntax error.
D. The loop executes exactly once.

24 What is the "Dangling Else" problem?

A. When an else has no matching if.
B. Ambiguity regarding which if an else belongs to in nested structures.
C. Using else with a switch statement.
D. Writing else on a new line.

25 What is the size of a long double in standard C (architecture dependent, but generally)?

A. Always 4 bytes
B. Always 8 bytes
C. At least 10 bytes (often 12 or 16)
D. Same as int

26 Which function is defined in <conio.h> (non-standard) to read a character without echoing it to the screen?

A. getchar()
B. scanf()
C. getch()
D. getche()

27 Consider the following code: int x = 10; float y = x;. What type of conversion is this?

A. Explicit casting
B. Implicit conversion (Type Coercion)
C. Dynamic casting
D. Static casting

28 Which of the following is true about the default case in a switch statement?

A. It must appear as the last case.
B. It is mandatory.
C. It executes if no other case matches.
D. It requires a continue statement.

29 How do you print the % symbol using printf?

A. \%
B. %%
C. %
D. \p

30 What is the correct syntax for a do-while loop?

A. do { //code } while(condition)
B. do { //code } while(condition);
C. while(condition) do { //code };
D. do while(condition) { //code }

31 What is the output of: printf("%d", 1 ? 2 : 3);?

A. 1
B. 2
C. 3
D.

32 Which loop is generally preferred when the number of iterations is known beforehand?

A. while
B. do-while
C. for
D. goto

33 In the statement scanf("%d", &a);, what does the & symbol represent?

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

34 What is the output of printf("%0.2f", 3.14159);?

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

35 Which statement is used to bypass the conditional check of a loop and jump out immediately?

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

36 If int i = 0;, what is the value of i after while(i++ < 3);?

A. 2
B. 3
C. 4
D. 5

37 Which header file is typically required for standard I/O functions like printf and scanf?

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

38 Can a switch statement use a float variable as a case label?

A. Yes
B. No
C. Only in C++
D. Only if typecast to int

39 What is the result of (int)3.99?

A. 4
B. 3
C. 3.99
D.

40 Which of the following is considered 'unformatted' I/O?

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

41 Which logical operator allows an if statement to execute if at least one of two conditions is true?

A. &&
B. ||
C. !
D. &

42 What is the ASCII range for standard char type (signed)?

A. 0 to 255
B. -128 to 127
C. -32768 to 32767
D. 0 to 65535

43 What happens if you assign a value larger than the maximum range to a variable (Overflow)?

A. The program crashes.
B. The value wraps around (undefined behavior in signed, modulo arithmetic in unsigned).
C. The variable automatically expands.
D. The compiler fixes it.

44 What is the role of fflush(stdin)?

A. To clear the screen.
B. To clear the output buffer.
C. To clear the input buffer (undefined behavior in Standard C, but used in some compilers).
D. To flush memory to disk.

45 Which loop structure checks the condition at the 'Top' of the loop?

A. Entry Controlled
B. Exit Controlled
C. Bottom Checked
D. Post-Test

46 What is the syntax for a block of code (compound statement) in C?

A. ( ... )
B. [ ... ]
C. { ... }
D. < ... >

47 If you want to read a hexadecimal number input into an integer variable, which format specifier applies?

A. %d
B. %o
C. %x
D. %h

48 What is the scope of variables declared inside the initialization part of a for loop (C99 standard and later)?

A. Global scope
B. Function scope
C. Block scope (local to the loop)
D. File scope

49 Which keyword is used to define a constant variable whose value cannot be changed?

A. static
B. const
C. volatile
D. immutable

50 In the expression a = b + c * d;, which operation is performed first?

A. Addition
B. Assignment
C. Multiplication
D. Left to right