Function call by value in C programming

Function call by value in C programming

//Function call by Value

#include<stdio.h>

int call(int);     //function declaration

main()
 {

   int i, y, a=100;

   y=call(a);     //function call(value of y is which function call return to main function by function definition)

   printf("Value of a:%d",a);    //so value of actual argument a not change if formal argument change
   printf("\n");

   printf("Value of y:%d",y);    //value of y is which function call return to main function
   printf("\n");

   call(a);    //function call

   printf("Value of a:%d",a);    //value of a not change
   printf("\n\n");
 
  for(i=0;i<a;i++)
  {
   call(a);    //function call until i<a which is 100. so loop run 100 times.function call also called 100 times
  }



 }

int call(int x)    //function definition.Here x argument/parameter bcuz value of a copy in x.
 {

  x=x+200;

  printf("Value of x:%d",x);
  printf("\n");

 return x;
 }


Related Posts