C++ Syntax Question:
Download Questions PDF

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:

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;
cout<<"The product of your two numbers is "<< mult ( x, y ) <<"n";

int mult ( int x, int y )
return x * y;

Download Basic C++ Syntax Interview Questions And Answers PDF

Previous QuestionNext Question
What is functions Syntax in C++?What is switch case in C++ Syntax?