function header and prototype in C++

logistic_guy

Full Member
Joined
Apr 17, 2024
Messages
790
Perform the task in each of the following statements:

\(\displaystyle \bold{a)}\) Write the function header for function zero that takes a long integer built-in array parameter bigIntegers and does not return a value.
\(\displaystyle \bold{b)}\) Write the function prototype for the function in part (a).
\(\displaystyle \bold{c)}\) Write the function header for function add1AndSum that takes an integer built-in array parameter oneTooSmall and returns an integer.
\(\displaystyle \bold{d)}\) Write the function prototype for the function described in part (c).
 
Perform the task in each of the following statements:

\(\displaystyle \bold{a)}\) Write the function header for function zero that takes a long integer built-in array parameter bigIntegers and does not return a value.
\(\displaystyle \bold{b)}\) Write the function prototype for the function in part (a).
\(\displaystyle \bold{c)}\) Write the function header for function add1AndSum that takes an integer built-in array parameter oneTooSmall and returns an integer.
\(\displaystyle \bold{d)}\) Write the function prototype for the function described in part (c).
show us your effort/s to solve this problem.
 
Before we answer \(\displaystyle \bold{a)}\) and \(\displaystyle \bold{b)}\), let us take a very basic example to plant the main idea in your brain.

When the function starts with the keyword \(\displaystyle \text{void}\), it means the function does not return a value.
An example is:😾

void cat(std::string name){
std::cout << "Welcome to my website " << name << "." << std::endl;
}

The header of this function is void cat(std::string name) and the prototype of this function is void cat(std::string);.
The difference between them is that the prototype ends with a semicolon and it's optional to include the name of the parameter.
In other words, void cat(std::string); and void cat(std::string name); are both valid prototypes functions. Therefore, the main difference between the header and the prototype of a function is that the latter must end with a simicolon.

When the function starts with the keyword \(\displaystyle \text{int}\), for example, it means the function returns an integer value when it is called.

An example is:🐶

int dog(int num1, int num2){
return num1*num2;
}

The header is int dog(int num1, int num2) and the prototype is int dog(int, int);.

Here is a screenshot. Look carefully at where it's written header and where it's written prototype to visualize the difference.

header_and_prototype.png

In the next post we'll answer \(\displaystyle \bold{a)}\) and \(\displaystyle \bold{b)}\).

💪🤡
 
\(\displaystyle \bold{a)}\)

The function header is: void zero(long int bigIntegers[])

\(\displaystyle \bold{b)}\)

The function prototype is: void zero(long int[]);
 
Top