1.

Arrays

Answer»
int main() {
string str[4] = {"Volvo", "BMW", "Volkswagen", "Ford"};
for(int i=0;i<4;i++){
cout << str[i]+ " ";
}
return 0;
}

Instead of defining individual variables for each item, arrays are used to hold these values of the same data type in a single variable. It stores the values in a contagious block of memory, that’s why we need to specify the number of values it is going to hold beforehand.

Declare an array by specifying the variable type, the array name enclosed in square brackets, and the number of elements it should store.




Discussion

No Comment Found