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 shows a correct prototype and a definition for adding two integers?

The key idea is that a function prototype and its definition must agree on the function’s signature: the return type, the function name, and the sequence and types of parameters. In the correct example, both the prototype and the definition declare int add(int a, int b) and the function body returns a + b. This exact match lets the compiler know what to expect when add is used and ensures the implementation satisfies that expectation. The other forms stray from that consistency in different ways: one mixes a void prototype with a returning definition, another flips the return type between prototype and definition, and another uses different parameter names between the prototype and the definition. While parameter names can be different in declarations and definitions in some contexts, keeping them aligned is the clearest demonstration of a matching prototype and definition.

The key idea is that a function prototype and its definition must agree on the function’s signature: the return type, the function name, and the sequence and types of parameters. In the correct example, both the prototype and the definition declare int add(int a, int b) and the function body returns a + b. This exact match lets the compiler know what to expect when add is used and ensures the implementation satisfies that expectation.

The other forms stray from that consistency in different ways: one mixes a void prototype with a returning definition, another flips the return type between prototype and definition, and another uses different parameter names between the prototype and the definition. While parameter names can be different in declarations and definitions in some contexts, keeping them aligned is the clearest demonstration of a matching prototype and definition.