-
Notifications
You must be signed in to change notification settings - Fork 0
/
C Operators.c
68 lines (49 loc) · 1.73 KB
/
C Operators.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
#include<stdio.h>
int main() {
int a = 10, b = 5, c = 2;
int result;
// Arithmetic operators
result = a + b; // Addition
printf("a + b = %d\n", result);
result = a - b; // Subtraction
printf("a - b = %d\n", result);
result = a * b; // Multiplication
printf("a * b = %d\n", result);
result = a / b; // Division
printf("a / b = %d\n", result);
result = a % b; // Modulus
printf("a %% b = %d\n", result);
// Relational operators
printf("a > b: %d\n", a > b);
printf("a == b: %d\n", a == b);
printf("a != b: %d\n", a != b);
// Logical operators
printf("(a > b) && (b > c): %d\n", (a > b) && (b > c));
printf("(a > b) || (b > c): %d\n", (a > b) || (b > c));
printf("!(a > b): %d\n", !(a > b));
// Assignment operators
result += 5; // result = result + 5
printf("result += 5: %d\n", result);
// Increment and decrement operators
a++; // Increment
printf("a++: %d\n", a);
b--; // Decrement
printf("b--: %d\n", b);
// Bitwise operators
result = a & b; // Bitwise AND
printf("a & b = %d\n", result);
result = a | b; // Bitwise OR
printf("a | b = %d\n", result);
result = a ^ b; // Bitwise XOR
printf("a ^ b = %d\n", result);
result = ~a; // Bitwise complement
printf("~a = %d\n", result);
result = a << 1; // Left shift
printf("a << 1 = %d\n", result);
result = b >> 1; // Right shift
printf("b >> 1 = %d\n", result);
// Ternary operator
result = (a > b) ? a : b;
printf("Result of ternary operator: %d\n", result);
return 0;
}