Ask a Teacher



c++ function

Functions are the named unit of a group of program statements. Functions are of two types, they are pre defined functions and user defined functions.

Pre defined functions : Predefined functions are functions that are built into C++ Language to perform some standard operations. The functions that are stand alone used for general purposes and that are not depended on any classes are stored in the Standard Function Library. Some of the pre defined functions are as follows :
  • I/O Functions.
  • String and Character Functions
  • Mathematical Functions
  • Time,Date and Localization Functions.
  • Dynamic Allocation Function
  • Utility Functions
User defined functions :  C++ allows programmers to define their own functions. For example the following is a definition of a function which given the co-ordinates of a point (x,y) will return its distance from the origin.

float distance(float x, float y)
      // Returns the distance of (x, y) from origin
   {
    float dist;  //local variable
    dist = sqrt(x * x + y * y);
    return dist;
   }


comments powered by Disqus