Unit 3 - Practice Quiz

CSE109 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 of the function
B. To allocate memory for the function
C. To declare the function's name, return type, and parameters to the compiler
D. To call the function

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

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

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

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

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

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

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. <conio.h>
B. <stdlib.h>
C. <math.h>
D. <stdio.h>

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

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

8 What is the output of ceil(3.2)?

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

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

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

10 Where are auto variables stored in memory?

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

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. One
C. Zero
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. Hard Disk
B. RAM
C. Cache
D. CPU Registers

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

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

16 What is the scope of a global variable?

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

17 Consider the equation . Which C function call calculates ?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

25 What is the result of floor(3.9)?

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

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

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

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. register
B. auto
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 base case is at the end of the function
C. When the recursive call is the last executed statement in the function
D. When a function calls two other functions

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

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

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

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

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

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

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. No, because parameters are passed by value
B. Runtime Error
C. Yes, because integers are passed by reference
D. Yes, because swap is a keyword

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

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

35 Which mathematical function computes the base-10 logarithm?

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

36 What is 'Scope' in C programming?

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

37 Recursive functions are generally:

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

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

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

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

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

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

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

41 Which of the following is true about Formal Parameters?

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

42 The storage class extern is effectively the default for:

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

43 Which function computes ?

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

44 Can main() function be called recursively?

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

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

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

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. File scope
B. Global scope
C. Block scope (loop body)
D. Function scope

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

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

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

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

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

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