Unit 3 - Practice Quiz

CSE101 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What is the primary purpose of a function prototype in C?

A. To define the logic inside the function body
B. To call the function immediately
C. To tell the compiler about the function's name, return type, and parameters before its definition
D. To reserve memory for the function's local variables

2 If a function does not return a value, its return type must be declared as:

A. int
B. null
C. void
D. empty

3 In C, if a function is defined without specifying a return type, what is the default return type assumed by the compiler (in older C standards like C89)?

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

4 Consider the following function prototype: float compute(int x, double y);. Which of the following is a valid function call?

A. compute(5.5, 2);
B. int result = compute(5, 2.5);
C. float res = compute(5, 2.5);
D. compute(int 5, double 2.5);

5 What are actual parameters?

A. The variables defined in the function header
B. The values or variables passed to the function during a function call
C. The variables declared inside the main function
D. The return values of a function

6 In pass by value, what happens to the arguments passed to a function?

A. The address of the variable is passed
B. A copy of the value is made and passed to the called function
C. The called function accesses the original variable directly
D. The compiler throws an error if the value is modified

7 To simulate pass by reference in C, what must be passed to the function?

A. The value of the variable
B. The variable name as a string
C. The address (pointer) of the variable
D. The data type of the variable

8 Analyze the following code snippet. What is the output?

c
void modify(int a) {
a = 20;
}
int main() {
int x = 10;
modify(x);
printf("%d", x);
return 0;
}

A. 10
B. 20
C. 0
D. Garbage value

9 Which standard library header file must be included to use math functions like pow(), sqrt(), and sin()?

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

10 What is the return type of the standard library function sqrt(double x)?

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

11 Which function is used to calculate (x raised to the power of y)?

A. power(x, y)
B. exp(x, y)
C. pow(x, y)
D. raise(x, y)

12 What value does floor(3.8) return?

A. 3.0
B. 4.0
C. 3.8
D. 0.8

13 What value does ceil(3.2) return?

A. 3.0
B. 4.0
C. 3.2
D. 0.2

14 A function that calls itself is known as a _____ function.

A. Nested
B. Looping
C. Recursive
D. Self-referencing

15 What is the mandatory condition required in a recursive function to prevent infinite recursion?

A. Loop condition
B. Break statement
C. Base case
D. Return 0

16 What is the output of the following recursive function for fun(3)?

c
int fun(int n) {
if (n == 0) return 0;
return n + fun(n - 1);
}

A. 3
B. 5
C. 6
D. Infinite loop

17 Which of the following is a disadvantage of recursion compared to iteration?

A. Recursion is harder to read
B. Recursion uses more memory due to stack overhead
C. Recursion cannot solve mathematical problems
D. Recursion requires global variables

18 The region of a program where a variable is visible and accessible is called its:

A. Lifetime
B. Duration
C. Scope
D. Storage class

19 Where are global variables declared?

A. Inside the main function
B. Inside any user-defined function
C. Outside all functions
D. Inside a block { }

20 What happens if a local variable has the same name as a global variable?

A. Compiler Error
B. The global variable takes precedence
C. The local variable shadows (hides) the global variable within its scope
D. Both variables are merged

21 Which of the following is NOT a storage class specifier in C?

A. auto
B. static
C. internal
D. register

22 What is the default storage class for a variable declared inside a function block (e.g., int x;)?

A. static
B. extern
C. auto
D. register

23 What is the initial default value of an uninitialized auto variable?

A. Zero
B. One
C. Null
D. Garbage value

24 Where are auto variables stored in memory?

A. Heap
B. Stack
C. CPU Register
D. Data Segment

25 The register storage class suggests to the compiler that the variable should be stored in:

A. RAM
B. Hard Disk
C. CPU Registers
D. Cache Memory

26 Why can't we use the address-of operator (&) on a register variable?

A. It is illegal syntax
B. CPU registers do not have a memory address
C. Register variables are read-only
D. The compiler cannot optimize it

27 Which variable type is most suitable for a loop counter that requires very fast access?

A. extern
B. static
C. register
D. volatile

28 What is the default initial value of a static variable if not explicitly initialized?

A. Garbage value
B. Zero
C. One
D. Infinite

29 When is the memory for a static local variable deallocated?

A. When the function returns
B. When the block ends
C. When the program terminates
D. It is never deallocated

30 Predict the output:

c
void count() {
static int x = 0;
x++;
printf("%d ", x);
}
int main() {
count();
count();
return 0;
}

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

31 What does the extern keyword signify?

A. The variable is defined in the same block
B. The variable is defined in another file or later in the same file
C. The variable is constant
D. The variable is strictly local

32 If you want to restrict the visibility of a global variable to the file in which it is declared (preventing access from other files), which storage class should you use?

A. auto
B. extern
C. static
D. register

33 Which header file is required for the abs() function (integer absolute value)?

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

34 What is the result of fmod(5.3, 2.0)?

A. 2.0
B. 1.3
C. 1.0
D. 2.65

35 In C, parameter passing mechanism call by reference is achieved using:

A. Value types
B. Pointers
C. Arrays
D. Structures

36 What does the following prototype imply? void func(void);

A. The function takes one argument of type void
B. The function takes infinite arguments
C. The function takes NO arguments
D. The function returns an integer

37 Which storage class corresponds to the default behavior of global variables?

A. Internal Static
B. External (extern)
C. Auto
D. Register

38 What is the lifetime of an extern variable?

A. Function scope
B. Block scope
C. Throughout the program execution
D. Until the file is closed

39 Consider the code:
c
int a = 5;
void f() {
int a = 2;
printf("%d", a);
}

What is printed when f() is called?

A. 5
B. 2
C. 7
D. Error

40 What is 'Stack Overflow' in the context of recursion?

A. When the result is too large for an integer
B. When the memory assigned for the stack is exhausted due to deep recursion
C. When the heap memory is full
D. When the compiler crashes

41 Which function computes the sine of an angle (in radians)?

A. sine()
B. sin()
C. asin()
D. sinh()

42 If you define static int a; inside a function, where is it stored?

A. Stack
B. Data Segment
C. CPU Register
D. Cache

43 What is the output of fabs(-10.5)?

A. -10.5
B. 10.5
C. 10
D. 11

44 Which of the following creates a function that accepts a pointer to an integer?

A. void func(int a)
B. void func(int *a)
C. void func(int &a)
D. void func(*int a)

45 What is Indirect Recursion?

A. Function A calls Function A
B. Function A calls Function B, and Function B calls Function A
C. Function A calls Function B, which calls Function C
D. Function A uses a loop

46 Can main() function be called recursively in C?

A. No, never
B. Yes, it is allowed
C. Only in C++
D. Only if it has no arguments

47 Analyze the prototype: double *func(int a);. What does this function return?

A. A double value
B. A pointer to a double
C. A pointer to an integer
D. Nothing (void)

48 Which storage class allows a local variable to retain its value even after control exits the block where it is defined?

A. auto
B. register
C. extern
D. static

49 Which function allows swapping of two values visible in the main function?

A. void swap(int x, int y) { int t=x; x=y; y=t; }
B. void swap(int *x, int *y) { int t=*x; *x=*y; *y=t; }
C. int swap(int x, int y) { return x, y; }
D. void swap(int x, int y) { x = y; }

50 Why is the register storage class effectively deprecated or ignored by modern compilers?

A. Registers no longer exist in CPUs
B. Modern compilers are better at optimization and register allocation than humans
C. It causes compilation errors
D. It uses too much memory