by Dinesh Thakur Category: Function and Pointer

We know that the C language uses the call by value mechanism to pass parameters and that a function parameter is a copy of the argument specified in the function call.

 

Thus, a function parameter can be modified without affecting the corresponding argument in the calling function. This fact can often be used effectively to save some memory. Consider function fact given below to determine the factorial of an integer number.

#include <stdio.h>

#include <conio.h>

void main ()

{

           int a;

           long f,fact();

           clrscr();

           printf ("\n Enter a Number : ");

           scanf ("%d",&a);

           f=fact(a);

           printf ("\n The Factorial of %d is : %ld",a,f);

           getch();

}

       long int fact(int n)

{

     int i;

     int fact = 1;

     for (i = n; i > 1; i--)

     fact *= i;

     return fact;

}

       Function Parameter as a Loop Variable



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles