srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/languages/c.md
blob: 6b5ae6d8b319fce1ea2d53d40f346d5ff094f52a (plain) (blame)
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
170
171
172
173
174
175
176
177
178
## C Programming  

### Basic Syntax  
- Comments  
```c  
 // This is a single-line comment  
  
 /* This is a  
    multi-line comment */  
```  
  
- Variables  
```c  
// Declaration and initialization  
int x = 10;  
  
// Declaration without initialization  
float y;  
```  

 ###### Data Types  

| Data | Type | Description|  
|  --- | --- | --- |  
| int | Integer | Represents whole numbers without a fractional component |  
| float | Floating point number | Represents real numbers with a single-precision format |  
| double | Double precision floating point number | Represents real numbers with a double-precision format |  
| char | Character | Represents a single character, such as a letter or symbol |  
| bool | Boolean | Represents a logical value, either true or false |  

 ###### Operators  
- Arithmetic Operators:

| Operator | Name | Description |   
|  --- | --- | --- |  
| + | Addition | Adds two operands |  
| - | Subtraction | Subtracts the right operand from the left operand |  
| * | Multiplication | Multiplies two operands |  
| / | Division | Divides the left operand by the right operand |  
| % | Modulus (remainder after division) | Computes the remainder after division of two operands |  

  - Assignment Operators:

| Operator | Name | Description |   
|  --- | --- | --- |  
| = | Assignment | Assigns a value to a variable |  
| += | Addition Assignment | Adds right operand to the left operand and assigns the result to the left operand |
| -= | Subtraction Assignment | Subtracts right operand from the left operand and assigns the result to the left operand |
| *= | Multiplication Assignment | Multiplies the left operand by the right operand and assigns the result to the left operand |
| /= | Division Assignment | Divides the left operand by the right operand and assigns the result to the left operand |
| %= | Modulus Assignment | Computes the modulus of the left operand with the right operand and assigns the result to the left operand |

  - Comparison Operators:

| Operator | Name | Description |   
|  --- | --- | --- |  
| == | Equality | Checks if two operands are equal |  
| != | Inequality | Checks if two operands are not equal |  
| < | Less than | Checks if the left operand is less than the right operand |  
| > | Greater than | Checks if the left operand is greater than the right operand |  
| <= | Less than or equal to | Checks if the left operand is less than or equal to the right operand |  
| >= | Greater than or equal to | Checks if the left operand is greater than or equal to the right operand |  

  - Increment and Decrement Operators

| Operator | Name | Description |   
|  --- | --- | --- |  
| ++ | Increment | Increments the value of a variable by 1 |
| -- | Decrement | Decrements the value of a variable by 1 |

  - Bitwise Shitfers

| Operator | Name | Description |   
|  --- | --- | --- |  
| << | Left Shift | Shifts the bits of the left operand to the left by the number of positions specified by the right operand |
| >> | Right Shift | Shifts the bits of the left operand to the right by the number of positions specified by the right operand |

  - Bitwise Operators

| Operator | Name | Description |   
|  --- | --- | --- |  
| &  | Bitwise AND | Performs bitwise AND operation |
| \| | Bitwise OR | Performs bitwise OR operation |
| ^  | Bitwise XOR | Performs bitwise XOR (exclusive OR) operation |
| ~  | Bitwise NOT | Inverts the bits |

  - Logical Operators

| Operator | Name | Description |   
|  --- | --- | --- |  
| && | Logical AND | Performs logical AND operation |  
| \|\| |Logical OR | Performs logical OR operation |  
| ! | Logical NOT | Negates the value of a condition |  

- - -  
  
##### Control Structures  
- Conditional Statements  
```c  
if (condition) {  
    // code block to execute if condition is true  
} else if (anotherCondition) {  
    // code block to execute if anotherCondition is true  
} else {  
    // code block to execute if neither condition is true  
}  
```  
- Switch Statements  
```c  
switch (expression) {  
    case value1:  
        // code block to execute if expression equals value1  
            break;  
              case value2:  
                  // code block to execute if expression equals value2  
                      break;  
                        default:  
                            // code block to execute if expression does not equal any specified value  
                                break;  
}  
```  
- For Loop  
```c  
for (initialization; condition; update) {  
    // code block to execute repeatedly while condition is true  
}  
```  
  
- While Loop  
```c  
while (condition) {  
    // code block to execute repeatedly while condition is true  
}  
```  
  
- Do-While Loop  
```c  
do {  
    // code block to execute at least once  
} while (condition);  
```  
  
- - -  
  
##### Functions  
```c  
// Function prototype  
returnType functionName(argumentType argumentName);  
  
// Function definition  
returnType functionName(argumentType argumentName) {  
    // code block to execute  
      return returnValue;  
}  
```  
  
- - -  
  
##### Arrays  
```c  
// Declaration and initialization  
int arrayName[size] = {value1, value2, value3};  
  
// Accessing elements  
int element = arrayName[index];  
```  
  
- - -  
  
##### Pointers  
```c  
// Declaration and initialization  
int *pointerName = &variableName;  
  
// Accessing value through pointer  
int value = *pointerName;`  
```