Unit 3 - Practice Quiz

CSE109

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

A. To define the logic of the function
B. To call the function
C. To declare the function's name, return type, and parameters to the compiler
D. To allocate memory for the function

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

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

3 In the context of function calls, what are 'actual parameters'?

A. Parameters defined in the function prototype
B. Parameters defined in the function definition header
C. Arguments passed to the function during the function call
D. Variables declared inside the function body

4 What happens when you pass parameters by value (Call by Value)?

A. The address of the variable is passed
B. A copy of the variable's value is passed to the function
C. The function can directly modify the original variable
D. The variable is declared as global

5 Which of the following is strictly necessary for a recursive function to stop?

A. A return statement returning 0
B. A global variable
C. A base case (termination condition)
D. A goto statement

6 Which header file is required to use mathematical functions like pow() and sqrt()?

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

7 What is the return type of the sqrt() function in C?

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

8 What is the output of ceil(3.2)?

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

9 What is the default storage class for a local variable declared inside a function block?

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

10 Where are auto variables stored in memory?

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

11 Which storage class allows a local variable to retain its value between multiple function calls?

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

12 What is the default initial value of an uninitialized variable with the static storage class?

A. Garbage value
B. Zero
C. One
D. Depends on the compiler

13 Which keyword is used to declare a variable that is defined in another file?

A. global
B. import
C. extern
D. remote

14 A variable declared with the register storage class is stored in:

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

15 Which of the following operations is NOT allowed on a register variable?

A. Incrementing the value
B. Printing the value
C. Taking the address using the & operator
D. Using it in a loop

16 What is the scope of a global variable?

A. Inside the main function only
B. Inside the function where it is declared
C. Throughout the entire program (file scope)
D. Only inside if blocks

17 Consider the equation . Which C function call calculates ?

A. y = power(x, 3);
B. y = pow(x, 3);
C. y = exp(x, 3);
D. y = x ** 3;

18 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. Runtime Error

19 In the context of storage classes, what does 'Lifetime' refer to?

A. The region of code where the variable is visible
B. The duration for which the variable exists in memory
C. The data type of the variable
D. The number of times a variable is accessed

20 What is the correct syntax to define a function that takes two integers and returns an integer?

A. int func(int a, int b) { return a + b; }
B. void func(int a, int b) { return a + b; }
C. int func(a, b) { return a + b; }
D. func(int a, int b) : int { return a + b; }

21 Which of the following creates a 'Stack Overflow' error?

A. Defining too many global variables
B. Infinite recursion
C. Using float instead of double
D. Calling a function from main

22 What is the initial value of an uninitialized auto variable?

A. Zero
B. Null
C. Garbage (indeterminate) value
D. Previous value in register

23 Can a static global variable be accessed by other files using extern?

A. Yes, always
B. No, static restricts visibility to the file in which it is declared
C. Yes, if the compiler allows it
D. Only if included in a header file

24 Which mathematical function is used to calculate the absolute value of an integer?

A. fabs()
B. abs()
C. floor()
D. mod()

25 What is the result of floor(3.9)?

A. 3.0
B. 3.9
C. 4.0
D. 0.9

26 What does the function prototype void test(void); imply?

A. The function takes one argument of type void
B. The function takes any number of arguments
C. The function takes no arguments and returns nothing
D. The function returns a pointer to void

27 In C, arrays are always passed to functions by:

A. Value
B. Reference (conceptually, via pointer)
C. Copying the whole array
D. Global declaration

28 Which storage class is appropriate for a variable that acts as a counter for how many times a specific function is called?

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

29 What is 'Tail Recursion'?

A. When the recursive call is the first statement in the function
B. When the recursive call is the last executed statement in the function
C. When a function calls two other functions
D. When the base case is at the end of the function

30 Which of the following functions does not accept any arguments?

A. int fun(int n)
B. void fun(int a, int b)
C. int fun(void)
D. int fun(n)

31 If you do not specify a storage class, and the variable is declared inside main(), it is treated as:

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

32 What is the return type of fmod(double x, double y)?

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

33 Consider void swap(int a, int b) { int t=a; a=b; b=t; }. If called as swap(x,y), will x and y change in the caller?

A. Yes, because integers are passed by reference
B. No, because parameters are passed by value
C. Yes, because swap is a keyword
D. Runtime Error

34 How do you define a function that accepts an array of integers as a parameter?

A. void func(int arr)
B. void func(int arr[])
C. void func(array int)
D. void func(int [10] arr)

35 Which mathematical function computes the base-10 logarithm?

A. log()
B. ln()
C. log10()
D. exp()

36 What is 'Scope' in C programming?

A. The execution time of the program
B. The memory size of a variable
C. The region of the program where a variable is accessible
D. The type of value a variable holds

37 Recursive functions are generally:

A. Faster than iterative loops
B. More memory efficient than iterative loops
C. Slower and consume more memory than iterative solutions
D. Impossible to implement in C

38 What output does the following snippet produce? printf("%f", fabs(-5.5));

A. -5.500000
B. 5.500000
C. 5
D. Error

39 To modify the actual arguments in the calling function, parameters must be passed by:

A. Value
B. Name
C. Reference (pointers)
D. Register

40 If a function foo calls function bar, and bar calls foo, this is known as:

A. Direct Recursion
B. Indirect Recursion
C. Linear Recursion
D. Tail Recursion

41 Which of the following is true about Formal Parameters?

A. They are variables in the calling function
B. They are used in the function definition to receive values
C. They must be constants
D. They are global variables

42 The storage class extern is effectively the default for:

A. Local variables
B. Loop counters
C. Function definitions
D. Register variables

43 Which function computes ?

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

44 Can main() function be called recursively?

A. No, never
B. Yes, it is allowed
C. Only in C++
D. Only if it returns void

45 Which storage class specifies that a variable should be stored in the CPU for faster access?

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

46 Which of the following is a valid function prototype?

A. int sum(int x, int y)
B. int sum(int x, int y);
C. sum(int x, int y);
D. void sum{int x, int y}

47 What is the scope of a variable declared inside a for loop (e.g., for(int i=0;...) in C99 standard?

A. Global scope
B. Function scope
C. Block scope (loop body)
D. File scope

48 What happens if a recursive function has a base case but the recursive step does not move towards it?

A. It works correctly
B. It returns 0
C. Infinite recursion (Stack Overflow)
D. Compiler error

49 Which storage class is stored in the Data Segment of memory?

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

50 The trigonometric function sin(x) expects the angle to be in:

A. Degrees
B. Gradians
C. Radians
D. Minutes