Array:
An array is a data structure which stores multiple values of same types of data; the array values are stored in continuous memory locations.
- Size of an array has been declared inside a square bracket, which is named as size declarator.
- The size declarator must be declared as an integer with a value greater than “0” and the number inside the brackets represents the number of elements that the array can hold.
Syntax:
Syntax to declare an array,
data_type array_name[size_declarator];
Structure array:
- The structure needs an array if the items needs to be grouped together.
- Array is a “derived” data type and it contains similar elements.
- The array index starts with “0”.
- If the size of the array is 4, then the index values are “0”, “1”, “2”, and “3”.
Syntax:
struct_name array_name[size];
Example:
// Structure array declaration
Book name[20];
Explanation:
“Book” is a structure name, “name” is an array name and the value “20” is the “size” of the array.
Array named “forSale” to hold 35 “Car” structure:
The below is the declaration statement of the array named “forSale” to hold “35” cars structure with the first three elements defined:
/* array named forSale to hold 35 car structure with first three values initialized. */
Car forSale[35] = { Car("Ford ", "Taurus ", 2002, 21000),
Car("Honda", "Accord ", 2001, 11000),
Car("Jeep ", "Wrangler", 2004, 24000) };
Explanation:
- “Car” is a structure name, “forSale” is an array name and the value “35” is the size of the array.
- The above array is defined hold first three values that are given.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out With C++: Early Objects (10th Edition)
- Write a statement that declares a procedure-level one-dimensional array named intorders. The array should contain 15 elements.arrow_forward(Electrical eng.) Write a program that specifies three one-dimensional arrays named current, resistance, and volts. Each array should be capable of holding 10 elements. Using a for loop, input values for the current and resistance arrays. The entries in the volts array should be the product of the corresponding values in the current and resistance arrays (sovolts[i]=current[i]resistance[i]). After all the data has been entered, display the following output, with the appropriate value under each column heading: CurrentResistance Voltsarrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr