C++ Syntax Question:
Download Questions PDF

How to defines the function in C++?

Answer:

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 <iostream>

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;
}</iostream>

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?