Skip to content

Commit

Permalink
added C
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaanilkumar committed Jun 29, 2020
1 parent 9a1c1dd commit 4faf594
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions C/call_by_reference.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Call by reference example

#include <stdio.h>

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
}
19 changes: 19 additions & 0 deletions C/function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//Function example

#include <stdio.h>

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;
}
Empty file removed C/prog1.c
Empty file.

0 comments on commit 4faf594

Please sign in to comment.