C Arrays
Arrays, used to store multiple values in a single variable
To create an array, define the data type and specify the name of the array followed by square brackets [].
To insert values to it, use a comma-separated list, inside curly braces:
int myNumbers [] = {25, 50, 75, 100};
To access an arrelement, refer to its index number. Array indexes start with 0.
myNumbers[0] refers to 25.Code:
#include
int main() {
int myNumbers[] = {25, 50, 75, 100};
printf("%d", myNumbers[0]);
return 0;
}
Output
25
Explanation
Declare integer Array named myNumbers and store {25, 50, 75 100} to it (By using the syntax: type arrayName = {value1, value2, ……};).
To output first value of array, use format specifiers %d because here array contains integers.
You can change the value of a specific element, refer to the index number:
myNumbers [0]=33
• Now myNumbers[0] refers to 33.