What is the primary purpose of a function prototype in C?
a) To define the function body
b) To specify the function’s return type and parameters
c) To allocate memory for the function
d) To initialize a function
Answer:
b) To specify the function’s return type and parameters
Explanation:
A function prototype in C is a declaration of a function that specifies the function’s return type, name, and parameters (if any). It informs the compiler about the function’s interface, allowing the compiler to check the correctness of function calls made before the actual function definition is encountered. This helps in identifying errors related to incorrect function usage.
Understanding the purpose of function prototypes is crucial for writing correct and error-free C programs.