-
Notifications
You must be signed in to change notification settings - Fork 0
/
L6_Operator.c
171 lines (133 loc) · 1.92 KB
/
L6_Operator.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
void assignmentOperator()
{
int a,b,c;
printf("enter Value of A:");
scanf("%d",&a);
printf("enter Value of B:");
scanf("%d",&b);
//a = 3
//b = 4
c = a;
//c = 3
a = b;
//a = 4
b = c;
//b = 3
printf("new Value of A:%d\n",a);
printf("new Value of B:%d\n",b);
a+=3;
printf("new Value of A+3:%d\n",a);
}
void arithmeticOperator()
{
int a=10;
int b = 5;
int c = a+b; //5
//printf("%d",c);
//a+b-c*d/e
//BODMAS
int bodmas = (((10+5)-3)*6/2);
printf("%d",bodmas);
}
void relationalOperator()
{
//>,<,>=,<=,==,!=
//true|false=boolean
// 1 | 0 = int
int a =10;
int b = 10;
int c = a==b; //true = 1
printf("%d",c);
}
void logicalOperator()
{
//&&,||,!
int a =40;
int b = 10;
int z = 10;
int x = 20;
int con = (a==b)||(z==x);
printf("%d",con);
}
void bitwiseOperator()
{
//&,|,^,>>,<<
int a = 1;
int b = 2;
//c = a&b;
//8421
//0001
//0010
//0011
//0010<<1
//0100
//printf("%d",a|b);
printf("%d",b<<1);
}
void elvisOperator()
{
//?
int a = 10;
int b = a==10?5:6;
printf("%d",b);
}
void sizeOfOperator()
{
int a = 10;
char c = 'c';
printf("%d",sizeof(c));
}
void starAndMemoryOperator()
{
//*,&
//6421996
int a = 10;
int *b = &a;
printf("%d\n",&a);
printf("%d",b);
printf("%d",*b);
}
void swapProgram()
{
int a = 10; //Acctual
int b = 11;
swapByRef(&a,&b);
printf("a:%d\n",a);
printf("b:%d\n",b);
}
void swapByValue(int a,int b)
{
int tmp = a;
a = b;
b=tmp;
printf("a:%d\n",a);
printf("b:%d",b);
}
void swapByRef(int *a,int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b=tmp;
}
void dotAndArrowOperator()
{
//. ->
struct
{
int age;
int id;
}emp;
emp.age = 21;
emp.id = 1;
printf("Age%d\n",emp.age);
printf("Id%d",emp.id);
}
void tempConverter()
{
float tempInFahrenheit;
printf("Enter temp in Fahrenheit\n");
scanf("%f",&tempInFahrenheit);
float tempInCelcius = (tempInFahrenheit-32)/1.8;
printf("Temp in Celsius%f",tempInCelcius);
}