Friday, 21 March 2014

FUNCTIONS IN C

                            FUNCTIONS

A function is a self contained block of statements that perform a task of some kind. More basically they can be called as the building blocks of C. Without function C cannot work. Beginners must have observed that every program in C has abody that begins with main(). This main() is basic function  of C. Apart from function main any body can define their own function according to their needs. An example of which is 
                                   float power(float x)
                                     {
                                             float sum;
                                             sum=x*x;
                                       }            
So here i have defined a function named power which would calculate the square of the input number.

If a program contains only one function, it  should be main() .
Lets give an example to clear concept----
                     #include<stdio.h>
                      void power()
                       {
                                     printf("I am very powerfull");
                       }
                      void main()
                     {
                                printf("hi!");
                                power();
                      }
             The output would be as----
                               
                                  hi!
                                  I am very power full

No comments:

Post a Comment