Declare an Array in C
-Declare an Array
-Syntax of an Array
-How to initialize an Array
Arrays
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.
To create an array, define the data type (like int
) and specify the name of the array followed by square brackets [].
data_type array_name [array_size];
Float Data Type Array Declaration and Initialization:
To insert values to it, use a comma-separated list, inside curly braces:
Integer Data Type Array Declaration and Initialization:
int myNumbers[4] = { 25, 50, 75, 100 };
Float Data Type Array Declaration and Initialization:
float myNumbers[4] = { 25.50, 50.20, 75.00, 100.60 } ;
Char Data Type Array Declaration and Initialization:
char myChar[4] = { 'c', 'h', '$', '*' } ;
char myChar[4] = { 'c', 'h', '$', '*' } ;
Comments
Post a Comment