Type of Array | Initialization | Link |
---|---|---|
Integer Array | int intArray[5] = {1, 2, 3, 4, 5}; |
Learn More |
Character Array | char charArray[5] = {'a', 'b', 'c', 'd', 'e'}; |
Learn More |
Float Array | float floatArray[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; |
Learn More |
Double Array | double doubleArray[5] = {1.111, 2.222, 3.333, 4.444, 5.555}; |
Learn More |
Long Array | long longArray[5] |
Learn More |
Short Array | short shortArray[5] = {1, 2, 3, 4, 5}; |
Learn More |
Unsigned Integer Array | unsigned int unsignedIntArray[5] = {1, 2, 3, 4, 5}; |
Learn More |
Unsigned Long Array | unsigned long unsignedLongArray[5] |
Learn More |
Unsigned Short Array | unsigned short unsignedShortArray[5] = {1, 2, 3, 4, 5}; |
Learn More |
Boolean Array (Using int) | int boolArray[2] = {1, 0}; // true, false |
Learn More |
In C programming, you can declare and initialize an array in various ways. Here are some common methods:
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[5]; for (int i = 0; i < 5; i++) { arr2[i] = i + 1; }
int arr3[5] = {1, 2}; // arr3[0] = 1, arr3[1] = 2, arr3[2] = 0, arr3[3] = 0, arr3[4] = 0
int arr4[5] = {[0] = 1, [2] = 3}; // arr4[0] = 1, arr4[1] = 0, arr4[2] = 3, arr4[3] = 0, arr4[4] = 0
char str[] = "Hello"; // str[0] = 'H', str[1] = 'e', ..., str[4] = 'o', str[5] = '\0'