Function in C++ : Function is defined as block of code which is used to perform a specific task. It can run only when we call it by its name in main function.
Syntax for creating function in c++:
void sum(int a , int b)
cout<<”Enter a number”<<endl;
cout<<”Enter another number<endl;
Enter a number 5
Enter another number 4
Inline Function in C++:
An inline function is a function that is expanded in line when it is invoked. Inline expansion makes a program run faster because the overhead of a function call and return is eliminated. It is defined by using key word [inline].
Syntax for creating an inline function:
# include <iostream.h>
inline int sum(int a, int y)
inline int mul(int a, int b)
int b = 4;
Properties of Inline Function:
1.Inline function sends request but not a command to compiler.
2.Compiler my serve or ignore the request.
3.if function has too many lines of code or if it has complicated logic then it is executed as normal function.
1 thought on “Function In C++”
Pingback: Access Specifier in C++ - AskAtul.com