Constructs of C
Constructs of C
1. *Switch statements*:
```
switch (expression) {
case value1:
// code
break;
case value2:
// code
break;
default:
// code
```
Example:
```
int day = 2;
switch (day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
default:
printf("Other day");
```
```
```
Example:
```
int x = 5;
```
- *While loops*:
```
while (condition) {
// code
```
Example:
```
int i = 0;
while (i < 5) {
printf("%d", i);
i++;
```
```
```
do {
// code
} while (condition);
```
Example:
```
int i = 0;
do {
printf("%d", i);
i++;
```
```
```
// code
}
```
Example:
```
printf("%d", i);
```
```
#if condition
// code
#endif
```
Example:
```
#define DEBUG 1
#if DEBUG
printf("Debug mode");
#endif
```
These are the main conditional statements and constructs used in C programming. Let me know if you
have any further questions or need more examples!
1. If-else statements
2. Switch statements
1. While loops
2. Do-while loops
3. For loops
*Jump Statements:*
1. Break
2. Continue
3. Return
4. Goto
*Bitwise Operations:*
1. Bitwise AND (&)
2. Bitwise OR (|)
*Logical Operations:*
2. Logical OR (||)
*Comparison Operations:*
1. Equal to (==)
1. Assert statements
*Preprocessor Directives:*
1. #define
2. #include
3. #ifdef
4. #ifndef
5. #if
6. #else
7. #elif
8. #endif
*Operator Precedence:*
More specifically:
- `while`, `do-while`, and `for` are called *Looping Statements* or *Iteration Statements*
- 6.8 Statements
Understanding these control flow statements is essential for writing efficient and effective C programs.
More specifically:
- `while`, `do-while`, and `for` are called *Looping Statements* or *Iteration Statements*
Understanding these control flow statements is essential for writing efficient and effective C programs.
1. Conditional Statements
- If (`if`)
- If-else (`if-else`)
- Switch (`switch`)
2. Looping Statements
- While (`while`)
- Do-while (`do-while`)
- For (`for`)
3. Jump Statements
- Break (`break`)
- Continue (`continue`)
- Return (`return`)
- Goto (`goto`)
1. Assignment Statements
2. Arithmetic Statements
3. Bitwise Statements
- Bitwise OR (`|`)
*Function Constructs:*
1. Function definitions
2. Function calls
*Input/Output Constructs:*
*Miscellaneous Constructs:*
2. Expression statements