-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_as_parameter.c
More file actions
48 lines (40 loc) · 825 Bytes
/
struct_as_parameter.c
File metadata and controls
48 lines (40 loc) · 825 Bytes
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
//using call by value method//
#include <stdio.h>
struct rectangle
{
int length;
int breadth;
};
int area(struct rectangle r1)
//note: for call by reference just add * before r1 in above line//
{
length = length+1;
//above changes will not be executed in case of call by value and length will remain same//
return (r1.length * r1.breadth);
}
int main()
{
struct rectangle r = {3, 4};
area(r);
printf("%d",area(r));
return 0;
}
// call by address (will change the value of variables if done)//
#include <stdio.h>
struct rectangle
{
int length;
int breadth;
};
void change_length(struct rectangle *r1,int l)
{
(*r1).length = l;
// or r1 -> length = l;
}
int main()
{
struct rectangle r={19,45};
change_length(&r,50);
printf("%d",r.length);
return 0;
}