Defining functions (= methods) in C

  • Syntax to define a function in C:

       return-Type   functionName ( formal-parameters )
       {// function-body 
           local variables definitions
    
           statements
       } 

    Example: function that returns the square of a number

       float square( float x )                  
       {
          float r;         // Define a local variable         
    
          r = x * x;       // Statement
          return ( r );    // Return statement
       }