0% found this document useful (0 votes)
1 views

Constructs of C

Construct of c docs

Uploaded by

superprideofpink
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Constructs of C

Construct of c docs

Uploaded by

superprideofpink
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

In C, besides if-else statements, there are several other types of conditional statements and constructs

used for decision-making. Here are some examples:

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");

```

1. *Ternary operator* (Conditional Expression):

```

condition ? true_value : false_value

```

Example:

```

int x = 5;

int y = (x > 10) ? 20 : 10;

printf("%d", y); // Output: 10

```

1. *Loops with conditions*:

- *While loops*:

```

while (condition) {

// code

```

Example:

```

int i = 0;

while (i < 5) {
printf("%d", i);

i++;

```

```* **Do-while loops**:

```

```

do {

// code

} while (condition);

```

Example:

```

int i = 0;

do {

printf("%d", i);

i++;

} while (i < 5);

```

```* **For loops**:

```

```

for (init; condition; increment) {

// code

}
```

Example:

```

for (int i = 0; i < 5; i++) {

printf("%d", i);

```

1. *Conditional compilation* (using #if, #ifdef, #ifndef directives):

```

#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!

Here's a comprehensive list of conditional statements and constructs in C:


*Conditional Statements:*

1. If-else statements

2. Switch statements

3. Ternary operator (Conditional Expression)

4. Conditional compilation (#if, #ifdef, #ifndef)

*Loops with Conditions:*

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 (|)

3. Bitwise XOR (^)

4. Bitwise NOT (~)

5. Left shift (<<)

6. Right shift (>>)

*Logical Operations:*

1. Logical AND (&&)

2. Logical OR (||)

3. Logical NOT (!)

*Comparison Operations:*

1. Equal to (==)

2. Not equal to (!=)

3. Greater than (>)

4. Less than (<)

5. Greater than or equal to (>=)

6. Less than or equal to (<=)


*Miscellaneous:*

1. Assert statements

2. Error handling (errno, perror)

Some additional constructs include:

*Preprocessor Directives:*

1. #define

2. #include

3. #ifdef

4. #ifndef

5. #if

6. #else

7. #elif

8. #endif

*Operator Precedence:*

Understanding operator precedence is crucial for writing correct conditional statements.


Would you like more information on any of these topics or C programming in general?

In C programming, `do-while`, `for`, `if`, etc. are classified as:

*Control Flow Statements* or *Control Structures*

More specifically:

- `if` and `if-else` are called *Conditional Statements*

- `switch` is called a *Multiway Branch Statement*

- `while`, `do-while`, and `for` are called *Looping Statements* or *Iteration Statements*

- `break` and `continue` are called *Jump Statements*

- `return` is called a *Function Return Statement*

- `goto` is called an *Unconditional Jump Statement*

Collectively, these statements are also referred to as:

*Flow Control Constructs*


*Control Flow Constructs*

*Program Control Statements*

*Execution Control Statements*

In the C standard (ISO/IEC 9899:2011), these statements are categorized under:

- 6.8 Statements

- 6.8.1 Labeled statements

- 6.8.2 Compound statements

- 6.8.3 Expression and null statements

- 6.8.4 Selection statements (if, switch)

- 6.8.5 Iteration statements (while, do-while, for)

- 6.8.6 Jump statements (break, continue, return, goto)

Understanding these control flow statements is essential for writing efficient and effective C programs.

Would you like more information on C programming concepts?

In C programming, `do-while`, `for`, `if`, etc. are classified as:


*Control Flow Statements* or *Control Structures*

More specifically:

- `if` and `if-else` are called *Conditional Statements*

- `switch` is called a *Multiway Branch Statement*

- `while`, `do-while`, and `for` are called *Looping Statements* or *Iteration Statements*

- `break` and `continue` are called *Jump Statements*

- `return` is called a *Function Return Statement*

- `goto` is called an *Unconditional Jump Statement*

Collectively, these statements are also referred to as:

*Flow Control Constructs*

*Control Flow Constructs*

*Program Control Statements*

*Execution Control Statements*

In the C standard (ISO/IEC 9899:2011), these statements are categorized under:


- 6.8 Statements

- 6.8.1 Labeled statements

- 6.8.2 Compound statements

- 6.8.3 Expression and null statements

- 6.8.4 Selection statements (if, switch)

- 6.8.5 Iteration statements (while, do-while, for)

- 6.8.6 Jump statements (break, continue, return, goto)

Understanding these control flow statements is essential for writing efficient and effective C programs.

Would you like more information on C programming concepts?

`do-while`, `for`, `if`, etc. are indeed classified as:

*Constructs* or *Statements* in C programming

More specifically, they are categorized as:

*Control Flow Constructs* or *Control Structures*


Here's a comprehensive list of constructs/statement categories in C:

*Control Flow Constructs:*

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`)

*Data Manipulation Constructs:*

1. Assignment Statements

- Simple assignment (`=`)


- Compound assignment (`+=`, `-=`, `*=`, `/=`, `%=`)

2. Arithmetic Statements

- Unary operators (`+`, `-`, `!`, `~`)

- Binary operators (`+`, `-`, `*`, `/`, `%`)

3. Bitwise Statements

- Bitwise AND (`&`)

- Bitwise OR (`|`)

- Bitwise XOR (`^`)

- Bitwise NOT (`~`)

*Function Constructs:*

1. Function definitions

2. Function calls

*Input/Output Constructs:*

1. Input statements (`scanf`)

2. Output statements (`printf`)

*Miscellaneous Constructs:*

1. Null statements (`;`)

2. Expression statements

3. Labeled statements (`label:`)


4. Compound statements (`{ ... }`)

These constructs are the building blocks of C programming.

Would you like more information on C programming concepts?

You might also like