How Do You Use C Arrays In C++?
A C array is a data structure that stores many elements of the same data type. C arrays, when you use them in C++, are called “dumb” arrays. Arrays store default data types or user-defined ones in a contiguous area of memory. You can access an element via indexing, where the index is a positive integer that indicates the element’s position, counting from zero. Use the following convention to declare an array. Write the data type, use a name to designate the array and indicate the number of the elements inside square brackets. End the line with a semicolon. int arr1[5]; int arr2[5] = {0}; // arr2 has all zeros. Populate the array with data or initialize the array. Use indexing to assign elements to the various locations inside the array. Access the first location using an index of zero. Access the last location using an index of n minus one, where n is the length of the array: arr1[0] = 4; // puts 4 in the first location arr1[2] = 32; // puts 32 in the middle location arr1[4] = 17; // p