Arrays
int myNumbers[] = {25, 50, 75, 100};
printf("%d", myNumbers[0]);
// output 25
change array elements
int myNumbers[] = {25, 50, 75, 100};
myNumbers[0] = 33;
printf("%d", myNumbers[0]);
Loop through the array
int myNumbers[] = {25, 50, 75, 100};
int i;
for (i = 0; i < 4; i++) {
printf("%d\n", myNumbers[i]);
}
set array size
// Declare an array of four integers:
int myNumbers[4];
// add element
myNumbers[0] = 25;
myNumbers[1] = 50;
myNumbers[2] = 75;
myNumbers[3] = 100;
Comments