-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a1c1dd
commit 4faf594
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |