For 1D Array:
int a[5] = {10, 20, 30, 40, 50};You can also omit the size:
int a[] = {1, 2, 3}; // size automatically becomes 3Partial Initialization:
int a[5] = {1, 2}; // Remaining elements will be 0For 2D Arrays:
int b[2][3] = {
{1, 2, 3},
{4, 5, 6}
};or:
int b[2][3] = {1, 2, 3, 4, 5, 6}; // Same resultUninitialized Arrays:
If you don’t initialize explicitly:
int arr[5];- The content is garbage (undefined), unless declared globally or statically (which will default to zero).
Example Code (Initialization and Access):
#include <stdio.h>
int main() {
int scores[5] = {90, 85, 78, 92, 88};
printf("Student Scores:\n");
for (int i = 0; i < 5; i++) {
printf("Student %d: %d\n", i + 1, scores[i]);
}
return 0;
}Output:
Student 1: 90
Student 2: 85
Student 3: 78
Student 4: 92
Student 5: 88