From 4faf594e202a93e58baee2ed884f0ffe86c71632 Mon Sep 17 00:00:00 2001 From: adithyaanilkumar Date: Mon, 29 Jun 2020 09:38:46 +0530 Subject: [PATCH] added C --- C/call_by_reference.c | 18 ++++++++++++++++++ C/function.c | 19 +++++++++++++++++++ C/prog1.c | 0 3 files changed, 37 insertions(+) create mode 100644 C/call_by_reference.c create mode 100644 C/function.c delete mode 100644 C/prog1.c 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