diff --git a/C/call_by_reference.c b/C/call_by_reference.c new file mode 100644 index 0000000..4c99dd6 --- /dev/null +++ b/C/call_by_reference.c @@ -0,0 +1,18 @@ +// Call by reference example + +#include + +void mathoperations(int x, int y, int *s, int *d); +void main() +{ + int x=20, y=10, s, d; // x and y input arguments, s and d output arguments + mathoperations(x, y, &s, &d); + printf(" s=%d\n d=%d\n", s,d); +} + + +void mathoperations(int a, int b, int *sum, int *diff) // x to a, y to b, address of s to sum and address of d to diff +{ + *sum=a+b; //sum and diff are pointer variables + *diff=a-b; //*sum and *diff are pointers +} \ No newline at end of file diff --git a/C/function.c b/C/function.c new file mode 100644 index 0000000..8fb8d30 --- /dev/null +++ b/C/function.c @@ -0,0 +1,19 @@ +//Function example + +#include + +int sum(int a, int b); // function declaration or prototype +void main() +{ + int num1=10,num2=20,result; + result=sum(num1,num2); //function call + printf("Sum of numbers is: %d",result); + +} + +int sum(int a, int b) // Function header +{ +int s; +s=a+b; +return s; +} \ No newline at end of file diff --git a/C/prog1.c b/C/prog1.c deleted file mode 100644 index e69de29..0000000