Function c++ [What is function c++] - leo tutorials

What is Function in C++

function c++: 
If a program is divided into functional parts, then each part may be independently coded and later combined into a single unit. These sub programs called functions.
          We use the following syntax for developing a program of function:

Syntax :

function declaration
   function call
function definition
   function body 

   when the function is called, control is transferred to the first statement in the function body. The other statements in the function body are then executed and control returns to the main program when the closing brace is encountered.
           The advantages of functions are as follows:

Advantages :

  • The length of a source program can be reduced by using functions at appropriate places.
  • It is easy to locate and isolate a faculty function for further investigations
  • A function may be used by many other programs.

                                 function c++

Main Function : The main function is defined as follows:

   //main program statements
This is perfectly valid in C because the main () in C doesnot return any value
    In C++, the main() returns a value of type int to the operating system. C++ therefore explicity defines main() as matching one of the following prototypes :

     int main()
     int main(int arg c, char*argv[])
The function that have a return value should use the return statement for termination. The main() function in C++ is therefore, defined as follows:

int main()
             return 0;
    since the return type of function is int by default , the keyword int in the main() header is optional. 

Post a comment