fork download
  1. #include <stdio.h>
  2. int add(int a, int b)//pass by value function
  3. {
  4. return a+b;
  5. }
  6.  
  7. int addr(int *c,int *d)//pass by reference function
  8. {
  9. return( *c + *d );
  10. }
  11.  
  12. int main()
  13. {
  14. //printf("Hello, World!\n");
  15. int a,b;
  16. printf("enter 2 digits");
  17.  
  18. scanf("%d%d", &a,&b);
  19. printf("there sum is %d",add(a,b)); //invoking pass by value
  20.  
  21. int *p; //creating a pointer to variable
  22. p=&a;
  23. *p=26;
  24.  
  25. printf("\nmodified value of a is %d",a);
  26.  
  27. printf("\n using reference\n");
  28. printf("%d",addr(&a,&b)); //invoking pass by reference function
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 2056KB
stdin
Standard input is empty
stdout
enter 2 digitsthere sum is 1999170649
modified value of a is 26
 using reference
-1218941337