Answers

Question and Answer:

  Home  Basic C++ Syntax

⟩ How to defines the function in C++?

When the programmer actually defines the function, it will begin with the prototype, minus the semi-colon. Then there should always be a block with the code that the function is to execute, just as you would write it for the main function. Any of the arguments passed to the function can be used as if they were declared in the block. Finally, end it all with a cherry and a closing brace. Okay, maybe not a cherry.

Let's look at an example program:

#include

using namespace std;

int mult ( int x, int y );

int main()

{

int x;

int y;

cout<<"Please input two numbers to be multiplied: ";

cin>> x >> y;

cin.ignore();

cout<<"The product of your two numbers is "<< mult ( x, y ) <<"n";

cin.get();

}

int mult ( int x, int y )

{

return x * y;

}

 181 views

More Questions for you: