Question

In: Computer Science

Q1: What is the difference between function prototype and function definition in C++? Explain. Q2: What...


Q1: What is the difference between function prototype and function definition in C++? Explain.

Q2: What does function prototype consist off and what does function definition consists of? (hint: components)

Q3: Do the names of parameters have to agree in the prototype, definition, and call to the function? Why or why not, explain?

Solutions

Expert Solution

1)

Function Prototype:

A function prototype is a declaration of a function: its name, parameters and return type. Unlike a full definition, the prototype terminates in a semi-colon and it doesn't has body.

 int myfunc(double param) ;

The actual names of the parameter values (param in above example) can be left out of the prototype. This gives the flexibility of renaming variables at will.

Function definition:

The function definition tells the compiler what task the function will be performing.  A function definition cannot be called unless the function is declared and it has body.  

int myfunc(double param){

return param

}

2)

Function Prototype consists of its name, parameters and return type.

Function definition consists of body and can return value to the caller.

3) no need , The actual names of the parameter values (param in above example) can be left out of the prototype. This gives the flexibility of renaming variables at will.

// Screenshot of the code

// Sample output

// Code to copy

#include<iostream>
using namespace std;
// function prototype
int myfunc(double p);
int main(){
   // calling function
   cout<< myfunc(25);
   return 0;
}
// function definition
int myfunc(double param) {
   return param*2;
}


Related Solutions

Q1 what is the definition of knapsack problem ? Q2 what is the main difference between...
Q1 what is the definition of knapsack problem ? Q2 what is the main difference between salesman travelling problem and stagecoach problem ? please give short answer
arranged q1 to q2 to q3 a is between q1 and q2 b is between q2...
arranged q1 to q2 to q3 a is between q1 and q2 b is between q2 and q3 Let a=3 m, b=7 m, q1=2 C, q3=-3 C. What must q2 be for q1 to feel no net force. b) Let a=3 m, b=8 m, q1=4 C, q2=5 C, q3=-5 C. What is the magnitude of the electric field a distance c=4 m vertically above q2 i.e. located at (x,y)=(a,c)?
Q1 : In your own words, explain the difference between Routing and Forwarding. Q2 :In your...
Q1 : In your own words, explain the difference between Routing and Forwarding. Q2 :In your own words, compare between the architecture of the Infrastructure and Ad hoc Network Please I want text written answer, not on a paper thank you!
Explain the difference between the actual definition of a Riemann Integral of function f on the...
Explain the difference between the actual definition of a Riemann Integral of function f on the interval [a,b] and the conclusion of the FTOC Part 2.(Fundamental Theorem of Calculus Part 2)
Explain the difference between the actual definition of a Riemann Integral of function f on the...
Explain the difference between the actual definition of a Riemann Integral of function f on the interval [a,b] and the conclusion of the FTOC Part 2.(Fundamental Theorem of Calculus Part 2)
Q1. What is the scope of Productıon / Operations Management? Explain. Q2. Is there any difference...
Q1. What is the scope of Productıon / Operations Management? Explain. Q2. Is there any difference between Production Mgmt. and Operations Mgmt.? Explain. Q3. Why are Competitiveness, Productivity, Strategy and Flexibility crucial ( very important) for Organizations and Businesses? Explain. Q4. What are the benefits of applying Production Management concepts for organizations? Explain.
Q1: What is the difference between a democracy and a developed democracy? give examples. Q2: Why...
Q1: What is the difference between a democracy and a developed democracy? give examples. Q2: Why is the UK a developed democracy? Give evidence. Q3: Why is the origin of democracy found in both Greece and Rome, even though Rome is not technically a democracy? Q4: Why did the UK develop democratic institutions quicker than the rest of Europe? Q5: Why can presidential systems lead to a greater likelihood of divided government? Give an example. Q6: Why does the way...
Q1- What is the difference between centric and eccentric footings? How would they be used? Q2-...
Q1- What is the difference between centric and eccentric footings? How would they be used? Q2- In addition to isolated footings, what are some other types of footings, and how/where are they used? include the Harvard style reference for each answer.
Q1. What is the difference between a national culture and an organizational culture? Q2. Briefly Describe...
Q1. What is the difference between a national culture and an organizational culture? Q2. Briefly Describe the United Nations Global Contract. Q3. Do you think J. Biden (and son) are in compliance with the U.S. Corrupt Practices Act? Explain your answer.
C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and...
C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and the array dimensions as an input. The function should then square each value of the array in-place. At the completion of the function return a Boolean which indicates the process has completed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT