Foundations
Arrays
Arrays keep related values in order and let code read values by index.
Arrays
arrays.cpp
#include <iostream>
int main() {
int scores[3] = {82, 91, 76};
int bonus = ;
int firstScore = scores[0];
int adjustedScore = scores[1] + bonus;
std::cout << "first=" << firstScore << std::endl;
std::cout << "adjusted=" << adjustedScore << std::endl;
return 0;
}
#include <iostream>
int main() {
int scores[3] = {82, 91, 76};
int bonus = ;
int firstScore = scores[0];
int adjustedScore = scores[1] + bonus;
std::cout << "first=" << firstScore << std::endl;
std::cout << "adjusted=" << adjustedScore << std::endl;
return 0;
}
#include <iostream>
int main() {
int scores[3] = {82, 91, 76};
int bonus = ;
int firstScore = scores[0];
int adjustedScore = scores[1] + bonus;
std::cout << "first=" << firstScore << std::endl;
std::cout << "adjusted=" << adjustedScore << std::endl;
return 0;
}
array index
Array indexes start at zero, so `scores[0]` reads the first value.