Functions


Formally...

A function declaration in ANSI C has the form:
    result-type function-name( parameter-list )

    function-body


Examples

A function which has one integer as a parameter and returns an integer:
            /* Declare the function : */
            int times_two(int x) { 
                return x+x; 
              }

            ....

            /* Use the function : */
            printf("%d\n", times_two(8));
            printf("%d\n", times_two(a));


And one which returns no value...

            /* tea_message does not return a result */
            /* and has no parameters :              */
            void tea_message ( void ) { 
                printf("Time for tea!\n");
              }

            ...

            /* Display message : */
            tea_message();


...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_course_crash_in_c/_reml_grp/index.reml
On: 3/3/2003 at 17:43:41
Options: reml2 -i noindex -l long -o html -p multiple