-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepshallow.c
125 lines (87 loc) · 1.81 KB
/
deepshallow.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// code 4 deep and shallow copy
#include <stdio.h>
#include <string.h>
void change(int ar[],int n)
{
for(int i=0;i<n;i++)
{
ar[i]=ar[i]+5;
}
}
int change2(int x,int y)
{
x+=5;
y+=5;
printf("\n%d and %d",x,y);
return 0;
}
int main(void) {
int ar[]={10,20,30,40,50};
change(ar,5); //call by reference
//changes in called function will be reflected back
//to calling function (main)
printf("\nChanged Array\n");
for(int i=0;i<5;i++)
{
printf("%d ",ar[i]);
}
int a=100,b=200;
int x=change2(a,b); //call by value
//changes in called function will not be reflected back
//to calling function (main)
printf("\nChanged Values are %d and %d",a,b);
/*
int x=10,y;
y=x;
x+=5;
printf("X = %d",x);
printf("\nY = %d",y);
int x=10,*y;
y=&x; //y is containing address of x(*y is pointing to value of x)
*y=*y+5;
printf("X = %d",x);
printf("\nY = %d",*y);
x=x+10;
printf("\nX = %d",x);
printf("\nY = %d",*y);
*/
return 0;
}
// malloc() function toi create a dynamic array
#include <stdio.h>
int main()
{
int *p;
int n,i,s=0;
printf("Enter n");
scanf("%d",&n);
p=(int *)malloc(sizeof(int)*n);
printf("Enter elements in array\n");
for(int i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
for(int i=0;i<n;i++)
{
s=s+p[i];
}
printf("Sum = %d",s);
free(p);
return 0 ;
}
//code for enumeration
/*Enumeration (or enum) is a user
defined data type in C. It is mainly
used to assign names to integral constants,
the names make a program easy to read and maintain.
*/
// code that is using emnum data type
// user data type decleration ;
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};
int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}