forked from prasenjitghose36/MY-CODES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassing a function.cpp
79 lines (58 loc) · 1.09 KB
/
passing a function.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
//pass by value in function
#include<stdio.h>
add(int x, int y )
{
int z;
z = x+y;
return z;
}
int main()
{
int a,b,c;
printf("Enter two numbers to add them");
printf("\nEnter first number");
scanf("%d",&a);
printf("\nEnter second number\n");
scanf("%d",&b);
c = add (a,b);
printf("The Value after addition = %d",c);
}
//pass by address in parameter passing
#include <stdio.h>
void swap(int*, int*);
int main()
{
int x, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
}
//pass by reference in the function
#include<stdio.h>
void swap(int &a,int &b);
{
int temp;
temp = a;
a = b;
b = temp;
}
int main()
{
int x,y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(x, y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}