Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

Which of the following is a valid function prototype for adding two integers?

A function prototype declares how a function can be called: it specifies the return type and the parameter types, but provides no function body. For a function that adds two integers and returns their sum, you want the return type to be int and the two parameters to be int, followed by a semicolon. That is exactly what the valid prototype shows: int add(int a, int b); It tells the compiler what to expect when this function is called, without giving the implementation. The other forms include a body or use a return type that doesn’t match returning a value. A definition includes a body, so it’s not a prototype. A prototype with a void return type would declare a function that returns nothing, which can’t supply the sum. A prototype that includes a function body is not a prototype at all.

A function prototype declares how a function can be called: it specifies the return type and the parameter types, but provides no function body. For a function that adds two integers and returns their sum, you want the return type to be int and the two parameters to be int, followed by a semicolon. That is exactly what the valid prototype shows: int add(int a, int b); It tells the compiler what to expect when this function is called, without giving the implementation.

The other forms include a body or use a return type that doesn’t match returning a value. A definition includes a body, so it’s not a prototype. A prototype with a void return type would declare a function that returns nothing, which can’t supply the sum. A prototype that includes a function body is not a prototype at all.