Arrays in C
Arrays in C
---
---
- **Initialization**:
```c
data_type array_name[size] = {value1, value2, ..., valueN};
```
Example:
```c
int arr[5] = {1, 2, 3, 4, 5};
```
#### 4. 2D Arrays
- Represents a table of rows and columns.
- **Syntax**:
```c
data_type array_name[rows][columns];
```
Example:
```c
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
```
---
### Common Mistakes
1. **Out of Bounds Access**:
- Accessing indices beyond the size of the array leads to undefined
behavior.
2. **Uninitialized Arrays**:
- Using an uninitialized array can result in garbage values.
3. **Passing Arrays Incorrectly to Functions**:
- Always pass the correct size to avoid segmentation faults.