What is a function in C?
A
A data type B
A loop structure C
A block of code that performs a specific task D
A preprocessor directive
Analysis & Theory
A function is a reusable block of code designed to perform a specific task.
Which keyword is used to define a function that does not return a value?
A
void B
int C
main D
null
Analysis & Theory
`void` is used when a function does not return any value.
What is the return type of the `main()` function in C?
A
void B
int C
char D
float
Analysis & Theory
By convention, `main()` returns an `int` to indicate success or failure of the program.
What is the correct syntax to declare a function named `add` that returns an int and takes two int parameters?
A
int add(int, int); B
add int(int, int); C
int add(int x, int y) D
function add(int, int)
Analysis & Theory
Function declaration syntax: `return_type function_name(parameter_list);`
Where must a function be declared if it is defined after the `main()` function?
A
In a loop B
Inside `main()` C
Before `main()` or with a prototype D
It doesn’t matter
Analysis & Theory
You must declare the function prototype before `main()` if it’s defined later.
What does the `return` statement do in a function?
A
Terminates the program B
Skips to next line C
Returns control and a value to the caller D
Declares a variable
Analysis & Theory
`return` sends control and optionally a value back to the function’s caller.
What is the output?
```c
int square(int x) { return x * x; }
int main() { printf("%d", square(4)); }
```
A
4 B
8 C
16 D
Error
Analysis & Theory
`square(4)` returns `16`.
Can a function in C call itself?
A
No B
Only once C
Yes, it's called recursion D
Only in loops
Analysis & Theory
A function can call itself—this is known as recursion.
What is the default return type of a function if not specified (in older C)?
A
void B
int C
float D
char
Analysis & Theory
In old C (before C99), if no return type is specified, `int` is assumed by default.
Which statement is TRUE about function parameters in C?
A
They must be global variables B
They are passed by reference by default C
They are passed by value by default D
C does not support function parameters
Analysis & Theory
In C, arguments are passed by value by default, meaning a copy is passed.