Recall & Review
beginner
What is a function prototype in C?
A function prototype is a declaration of a function that specifies its name, return type, and parameters without the function body. It tells the compiler what to expect when the function is called.
Click to reveal answer
beginner
Why do we use function prototypes in C programs?
Function prototypes help the compiler check that functions are called with the correct number and types of arguments, preventing errors before the program runs.
Click to reveal answer
beginner
How do you write a function prototype for a function named
add that takes two integers and returns an integer?The prototype is: <br>
int add(int, int);Click to reveal answer
intermediate
What happens if you call a function without a prototype in C?
If a function is called without a prototype, the compiler assumes it returns an int and does not check the arguments, which can cause unexpected behavior or errors.
Click to reveal answer
beginner
Where should function prototypes be placed in a C program?
Function prototypes are usually placed at the top of the file or in a header file so that all parts of the program know about the functions before they are used.
Click to reveal answer
What does a function prototype in C specify?
✗ Incorrect
A function prototype tells the compiler the function's name, return type, and parameter types without the body.
Where is the best place to put function prototypes in a C program?
✗ Incorrect
Placing prototypes at the top or in header files ensures the compiler knows about functions before they are used.
What happens if you call a function without a prototype in C?
✗ Incorrect
Without a prototype, the compiler assumes the function returns int and does not check arguments, which can cause bugs.
Which of these is a correct function prototype for a function that returns void and takes no parameters?
✗ Incorrect
The correct prototype for a function with no parameters is
void func(void); to explicitly specify no arguments.Why is it important to match the function prototype with the function definition?
✗ Incorrect
Matching prototypes and definitions helps the compiler check calls and prevents errors.
Explain what a function prototype is and why it is useful in C programming.
Think about how the compiler knows what a function looks like before it is used.
You got /3 concepts.
Describe where and how you would declare function prototypes in a C program.
Consider program organization and compiler needs.
You got /3 concepts.