Unit 3 - Practice Quiz

CSE101

1 What is a function prototype in C?

A. A declaration that specifies the function's name, return type, and parameters but not the body.
B. The actual code implementation of the function.
C. A variable used to store the return value of a function.
D. A library file included at the top of the program.

2 In the function definition int add(int a, int b), what are a and b called?

A. Actual parameters
B. Formal parameters
C. Global variables
D. Constant arguments

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

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

4 Which of the following statements is true regarding the default return type of a function in C (C89 standard)?

A. The default return type is void.
B. The default return type is float.
C. The default return type is int.
D. There is no default return type; it must be specified.

5 What happens when a function is called by value?

A. The address of the actual arguments is passed to the function.
B. A copy of the value of the actual arguments is passed to the formal parameters.
C. The function can directly modify the actual arguments in the calling function.
D. Memory is allocated dynamically for the arguments.

6 Which operator is required to pass the address of a variable to a function in a 'call by reference' context?

A. * (Asterisk)
B. & (Ampersand)
C. -> (Arrow)
D. . (Dot)

7 Consider the function prototype: void swap(int *x, int *y);. This function uses:

A. Pass by value
B. Pass by reference (simulated using pointers)
C. Recursion
D. Static storage

8 Which header file must be included to use mathematical functions like sqrt() and pow()?

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

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

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

10 What does the function ceil(3.2) return?

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

11 What is a recursive function?

A. A function that calls another function.
B. A function that is defined inside another function.
C. A function that calls itself.
D. A function that has no return statement.

12 What is the essential condition required to stop infinite recursion?

A. Recursive case
B. Base case
C. Switch case
D. Loop case

13 If a recursive function does not have a base case, what runtime error is likely to occur?

A. Segmentation fault
B. Stack overflow
C. Heap corruption
D. Compilation error

14 Which mathematical sequence is classically calculated using recursion where ?

A. Factorial
B. Fibonacci
C. Geometric Progression
D. Armstrong numbers

15 What is the scope of a local variable?

A. The entire file.
B. The entire program.
C. The block or function in which it is defined.
D. Only the main function.

16 Where are global variables declared?

A. Inside the main function.
B. Inside a user-defined function.
C. Outside of all functions.
D. Inside a specific loop block.

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

A. Compiler error.
B. The global variable is used.
C. The local variable shadows the global variable within its scope.
D. Both variables share the same memory location.

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

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

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

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

20 Where are variables with the auto storage class stored?

A. CPU Registers
B. Stack memory
C. Heap memory
D. Data segment

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

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

22 Which storage class requests the compiler to store the variable in a CPU register for faster access?

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

23 Which operator cannot be applied to a variable with the register storage class?

A. Increment (++)
B. Assignment (=)
C. Address-of (&)
D. Addition (+)

24 What is the lifetime of a static local variable?

A. Only within the function call.
B. Until the next function call.
C. Throughout the entire execution of the program.
D. It depends on the scope.

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

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

26 When is a static variable initialized?

A. Every time the function is called.
B. Only once, before the program starts execution.
C. When the programmer manually assigns a value.
D. When the block is exited.

27 Which keyword is used to declare a variable that is defined in a different file?

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

28 A global variable declared with the static keyword has:

A. External linkage (visible to all files)
B. Internal linkage (visible only within the file)
C. No linkage
D. Dynamic scope

29 What does the function floor(4.9) return?

A. 4.0
B. 5.0
C. 4.9
D. 0.9

30 What is the correct syntax to define a function that takes an integer array as an argument?

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

31 In the expression result = pow(a, b);, what is the mathematical equivalent?

A.
B.
C.
D.

32 What is the scope of a function parameter?

A. Global scope
B. File scope
C. Function scope (local to the function)
D. No scope

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

A. auto
B. register
C. static and Global variables
D. None of the above

34 Consider int f(int n) { if(n==1) return 1; else return n*f(n-1); }. What does this calculate?

A. Sum of numbers up to n
B. Factorial of n
C. Fibonacci of n
D. Square of n

35 If you modify a static variable inside a function, what happens to its value when the function is called again?

A. It resets to zero.
B. It resets to its initial value.
C. It retains the modified value.
D. It becomes garbage.

36 What does the abs() function return?

A. The square root of a number.
B. The absolute value of an integer.
C. The absolute value of a float.
D. The power of a number.

37 Can a function definition be nested inside another function definition in standard C?

A. Yes, always.
B. No, standard C does not allow nested function definitions.
C. Yes, if the inner function is static.
D. Yes, if the inner function is void.

38 Which call is correct for a function declared as void compute(float *ptr, int val);?

A. compute(5.5, 10);
B. float f; compute(f, 10);
C. float f; compute(&f, 10);
D. compute(*f, 10);

39 What is 'Tail Recursion'?

A. When the recursive call is the very first statement.
B. When the recursive call is the very last operation performed by the function.
C. When a function has two recursive calls.
D. When recursion runs infinitely.

40 Which of the following functions generates a random number?

A. srand()
B. rand()
C. random()
D. generate()

41 When passing an array to a function, what is actually passed?

A. The entire array is copied.
B. The value of the first element.
C. The base address of the array (pointer to the first element).
D. The size of the array.

42 Which storage class specifier allows a global variable to be accessed by other files using extern?

A. static
B. No specifier (default global)
C. auto
D. register

43 What is the mathematical function fmod(x, y) used for?

A. Calculating
B. Calculating the floating-point remainder of
C. Calculating the absolute value
D. Calculating the logarithm

44 In a function signature int max(int, int);, the names of the parameters are:

A. Mandatory
B. Optional
C. Forbidden
D. Required to match the definition

45 What is the limit of the number of arguments a function can take?

A. Exactly 10
B. Exactly 255
C. Dependent on the compiler and system resources (specifically stack size).
D. Infinite

46 If you define a local variable auto int x; inside a loop, what happens to x in each iteration?

A. It retains the value from the previous iteration.
B. It is created and initialized (or left garbage) anew in each iteration.
C. It causes a compilation error.
D. It is treated as static.

47 Which keyword is used to return a value from a function?

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

48 What does extern int count; do?

A. Allocates memory for an integer count.
B. Initializes count to zero.
C. Declares that count is defined elsewhere, without allocating memory.
D. Creates a static variable.

49 Direct recursion is when function A calls function A. Indirect recursion is when:

A. Function A calls Function B, and Function B calls Function A.
B. Function A calls itself inside a loop.
C. Function A calls Function B, and Function B stops.
D. Function A returns a value to itself.

50 What is the return type of malloc() function?

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