# 2. Array Declaration and Initialization

### 2.1 Basic Array Declaration

**Python vs C Comparison:**

| Python | C |
|--------|---|
| `numbers = [1, 2, 3, 4, 5]` | `int numbers[5] = {1, 2, 3, 4, 5};` |
| `grades = []` | `float grades[100];` |
| `name = "Alice"` | `char name[10] = "Alice";` |

**C Array Declaration Syntax:**
```c
data_type array_name[size];
data_type array_name[size] = {value1, value2, ...};
```

### 2.2 Different Initialization Methods

#### 2.2.1 Complete Initialization
```c
int numbers[5] = {10, 20, 30, 40, 50};
char vowels[5] = {'a', 'e', 'i', 'o', 'u'};
float prices[3] = {12.5, 25.0, 8.75};
```

#### 2.2.2 Partial Initialization
```c
int scores[10] = {95, 87, 92};  // First 3 elements initialized
                                 // Remaining 7 elements = 0
char grades[5] = {'A', 'B'};     // grades[0]='A', grades[1]='B'
                                 // grades[2]=grades[3]=grades[4]='\0'
```

#### 2.2.3 Size Inference
```c
int data[] = {1, 2, 3, 4, 5};    // Size automatically becomes 5
char message[] = "Hello World";   // Size becomes 12 (including '\0')
```

#### 2.2.4 Zero Initialization
```c
int zeros[100] = {0};            // All elements initialized to 0
char buffer[50] = "";            // All characters initialized to '\0'
```

#### 2.2.5 Uninitialized Arrays (Dangerous!)
```c
int uninitialized[10];           // Contains garbage values!
// Always initialize arrays before use
```

### 2.3 Array Size and Memory

**Understanding Array Size:**
```c
int numbers[5];                  // 5 integers × 4 bytes = 20 bytes
char name[20];                   // 20 characters × 1 byte = 20 bytes
double values[10];               // 10 doubles × 8 bytes = 80 bytes

// Getting array size at compile time
int size = sizeof(numbers) / sizeof(numbers[0]);  // Result: 5
```

**Python vs C Size Operations:**
| Python | C |
|--------|---|
| `len(list)` | `sizeof(array) / sizeof(array[0])` |
| `list.append(item)` | Not possible with static arrays |
| `list.pop()` | Not possible with static arrays |