Recall & Review
beginner
What is a function declaration in C?
A function declaration tells the compiler about a function's name, return type, and parameters without giving the full body. It acts like a promise that the function will be defined later.
Click to reveal answer
beginner
What is a function definition in C?
A function definition provides the full body of the function, including the code that runs when the function is called.
Click to reveal answer
intermediate
Why do we use function declarations before definitions?
Function declarations allow the compiler to know about functions before they are used, so you can call functions before their full code appears in the file.
Click to reveal answer
beginner
Identify the function declaration and definition in this code:<br>
int add(int a, int b);<br>int main() {<br> return add(2, 3);<br>}<br>int add(int a, int b) {<br> return a + b;<br>}The line
int add(int a, int b); is the function declaration. The block starting with int add(int a, int b) { ... } is the function definition.Click to reveal answer
intermediate
Can a function be declared multiple times but defined only once?
Yes. You can declare a function many times (usually in header files), but you must define it only once to avoid errors.
Click to reveal answer
What does a function declaration in C NOT include?
✗ Incorrect
A function declaration includes the name, return type, and parameters but does NOT include the function's body.
Where should a function declaration usually be placed?
✗ Incorrect
Function declarations should appear before the function is called so the compiler knows about it.
What happens if you call a function without declaring or defining it first?
✗ Incorrect
The compiler will give an error because it does not know about the function.
Which of these is a correct function declaration?
✗ Incorrect
Option C is a proper function declaration with return type, name, and parameters, ending with a semicolon.
How many times should a function be defined in a C program?
✗ Incorrect
A function should be defined only once to avoid duplicate definition errors.
Explain the difference between a function declaration and a function definition in C.
Think about what the compiler needs to know before running the program.
You got /6 concepts.
Why is it important to declare functions before calling them in C programs?
Consider what happens if the compiler sees a function call it does not know about.
You got /6 concepts.