> ## Documentation Index
> Fetch the complete documentation index at: https://learn.acadlink.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Expressions and Statements

> Understanding expressions and different types of statements in C

# Expressions and Statements in C

***

## Expression

A combination of **operands** and **operators** that produces a value is called an **expression**.

```c theme={null}
c = a + b;
```

| Part        | Role                              |
| ----------- | --------------------------------- |
| `a` and `b` | Operands                          |
| `+`         | Arithmetic operator               |
| `=`         | Assignment operator               |
| `a + b`     | Expression (evaluates to a value) |

More examples:

```c theme={null}
x * y          // arithmetic expression
x > y          // relational expression (true/false)
x && y         // logical expression
x = 5          // assignment expression — returns 5
```

***

## Statement

A **statement** is a complete instruction in C that performs an action. Most statements end with a semicolon (`;`).

### Types of Statements

**Declaration Statement** — creates a variable:

```c theme={null}
int x;
```

**Assignment Statement** — assigns a value:

```c theme={null}
x = 10;
```

**Expression Statement** — evaluates an expression:

```c theme={null}
a + b;
x++;
```

**Function Call Statement** — calls a function:

```c theme={null}
printf("Hello");
scanf("%d", &x);
```

**Control Flow Statement** — changes execution order:

```c theme={null}
if (x > 0) { ... }
while (x < 10) { ... }
for (int i = 0; i < 5; i++) { ... }
```

**Compound Statement (Block)** — a group of statements enclosed in `{}`:

```c theme={null}
{
    int a = 5;
    int b = 10;
    int c = a + b;
}
```

A block is treated as a single unit. Variables declared inside a block are local to that block.

***

## Key Difference

|            | Expression          | Statement          |
| ---------- | ------------------- | ------------------ |
| Definition | Produces a value    | Performs an action |
| Example    | `a + b`             | `int a = 5;`       |
| Ends with  | No semicolon needed | Semicolon `;`      |
