Define function. List the components of C++ function.

Estudies4you
Q8. Define function. List the components of C++ function.
Answer : 
Functions :
Functions can be defined as components of a large program. They obtain values from the main( ) function, performs the operation and return the result to the calling function. Functions are reusable and make the debugging and modification of a program easier. They reduce the size of the program. 
They provide modularity of programs. 
Components of C++ Function
                 Components of C++ function are as follows,
  1. Function prototype declaration
  2. Function call
  3. Function definition
  4. Actual and formal arguments
  5. Return statement.

Q9. What is an Inline function?
Answer : 
Inline Function
Inline functions can be defined as functions which are expanded in line during its invocation.’ The declaration and definition of such functions can be done simultaneously.
Whenever, these functions are called, the compiler replaces the call with its respective function code. Generally, inline functions are used for executing small functions as it reduces the overhead incurred during the normal function call. Inlining means implicitly embedding the copy of the function body during its invocation.
The inline functions are declared using inline keyword which tells the compiler to replace the function call with the function code.

Syntax
inline func_name
{
statement 1;
statement 2;
..............
}

Example
inline float power( float x)
{
 return ( x*x);
}


Q10. Define preprocessor directives.
Answer :

Preprocessor directives are the lines of code which are included in the source file before program code. These are considered as special instructions because they tell the Preprocessor to process the source code (or) program before compilation. It always begins with a hash (#) symbol. A preprocessor directive is not closed with a semicolon (;).

Some of the preprocessor directives are as follows.
l. Source file inclusion
2. Macro definitions
3. Conditional inclusions
4. Line control
5. Error directive.

To Top