0
0
Cprogramming~5 mins

Function declaration and definition - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe function's return type
BThe function's name
CThe function's parameters
DThe function's body (code inside)
Where should a function declaration usually be placed?
ABefore the function is called
BAfter the function is defined
CInside the function body
DOnly in the main function
What happens if you call a function without declaring or defining it first?
ACompiler error
BProgram runs normally
CFunction is automatically declared
DFunction is ignored
Which of these is a correct function declaration?
Aint multiply(int x, int y) { return x * y; }
Bmultiply int(int x, int y);
Cint multiply(int x, int y);
Dint multiply x, y;
How many times should a function be defined in a C program?
AMultiple times
BOnce
CNever
DDepends on the number of calls
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.