Unit 3 - Practice Quiz
1 What is the primary purpose of a function prototype in C?
2 If a function does not return a value, its return type must be declared as:
int
null
void
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)?
void
int
float
char
4
Consider the following function prototype: float compute(int x, double y);. Which of the following is a valid function call?
compute(5.5, 2);
int result = compute(5, 2.5);
float res = compute(5, 2.5);
compute(int 5, double 2.5);
5 What are actual parameters?
6 In pass by value, what happens to the arguments passed to a function?
7 To simulate pass by reference in C, what must be passed to the function?
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;
}
9
Which standard library header file must be included to use math functions like pow(), sqrt(), and sin()?
<stdlib.h>
<conio.h>
<math.h>
<stdio.h>
10
What is the return type of the standard library function sqrt(double x)?
int
float
double
long double
11 Which function is used to calculate (x raised to the power of y)?
power(x, y)
exp(x, y)
pow(x, y)
raise(x, y)
12
What value does floor(3.8) return?
13
What value does ceil(3.2) return?
14 A function that calls itself is known as a _____ function.
15 What is the mandatory condition required in a recursive function to prevent infinite recursion?
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);
}
17 Which of the following is a disadvantage of recursion compared to iteration?
18 The region of a program where a variable is visible and accessible is called its:
19 Where are global variables declared?
{ }
20 What happens if a local variable has the same name as a global variable?
21 Which of the following is NOT a storage class specifier in C?
22
What is the default storage class for a variable declared inside a function block (e.g., int x;)?
static
extern
auto
register
23 What is the initial default value of an uninitialized auto variable?
24 Where are auto variables stored in memory?
25 The register storage class suggests to the compiler that the variable should be stored in:
26
Why can't we use the address-of operator (&) on a register variable?
27 Which variable type is most suitable for a loop counter that requires very fast access?
extern
static
register
volatile
28 What is the default initial value of a static variable if not explicitly initialized?
29 When is the memory for a static local variable deallocated?
30
Predict the output:
c
void count() {
static int x = 0;
x++;
printf("%d ", x);
}
int main() {
count();
count();
return 0;
}
31 What does the extern keyword signify?
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?
auto
extern
static
register
33
Which header file is required for the abs() function (integer absolute value)?
<math.h>
<stdlib.h>
<stdio.h>
<conio.h>
34
What is the result of fmod(5.3, 2.0)?
35
In C, parameter passing mechanism call by reference is achieved using:
36
What does the following prototype imply? void func(void);
37 Which storage class corresponds to the default behavior of global variables?
38 What is the lifetime of an extern variable?
39
Consider the code:
c
int a = 5;
void f() {
int a = 2;
printf("%d", a);
}
What is printed when f() is called?
40 What is 'Stack Overflow' in the context of recursion?
41 Which function computes the sine of an angle (in radians)?
sine()
sin()
asin()
sinh()
42
If you define static int a; inside a function, where is it stored?
43
What is the output of fabs(-10.5)?
44 Which of the following creates a function that accepts a pointer to an integer?
void func(int a)
void func(int *a)
void func(int &a)
void func(*int a)
45 What is Indirect Recursion?
46
Can main() function be called recursively in C?
47
Analyze the prototype: double *func(int a);. What does this function return?
48 Which storage class allows a local variable to retain its value even after control exits the block where it is defined?
auto
register
extern
static
49
Which function allows swapping of two values visible in the main function?
void swap(int x, int y) { int t=x; x=y; y=t; }
void swap(int *x, int *y) { int t=*x; *x=*y; *y=t; }
int swap(int x, int y) { return x, y; }
void swap(int x, int y) { x = y; }
50
Why is the register storage class effectively deprecated or ignored by modern compilers?