-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
63 lines (53 loc) · 1.95 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* File: main.c
* Author: a.skiadopoulos
*
* Created on 23 Φεβρουαρίου 2018, 11:19 πμ
*/
/* Call by Value and Call by Reference in C language
*
* If a function take any arguments, it must declare variables that accept the
* values as a arguments. These variables are called the formal parameters of
* the function.
* There are two ways to pass value or data to function which is given below;
* -Call by Value
* -Call by Reference */
/* function(s) declaration */
void call_byVal(int a, int b, int c);
void call_byRef(int *a, int *b, int *c);
/* library input */
#include <stdio.h>
#include <conio.h>
/* main method */
int main() {
//int argc, char** argv
/* local variable(s) definition */
int num1 = 100, num2 = 200, num3 = 500;
char ch;
/* printout header */
printf("\n --- Functions Call by Value & Call by Reference ---\n\n");
/* Call by Value */
printf("\n- Values before Call by Value: {%d, %d, %d}\n", num1, num2, num3);
call_byVal(num1, num2, num3);
printf("\n- Values after Call by Value: {%d, %d, %d}\n", num1, num2, num3);
/* Call by Reference */
printf("\n- Values before Call by Reference: {%d, %d, %d}\n", num1, num2, num3);
call_byRef(&num1, &num2, &num3);
printf("\n- Values after Call by Reference: {%d, %d, %d}\n", num1, num2, num3);
printf("\n\nNOTICE: Function with different calling methods tries to SWAP values between\n"
" the first two numbers as well as REDUCE the value of the third number.\n");
printf("\n\n");
/* loop used for checking a specific ASCII character */
do
{
printf("\nPress [Esc] key to exit...");
ch = getch();
} while(ch != 27);//27 is the ASCII code for ESC key
printf("\n\n");
return 0;
}
/*
* function getch();
* Is used to catch a single character from the keyboard (not showed on screen)
* and returns the corresponding ASCII value (typically integer value).
*/