Programming in C++ What if you wanted to store and total 1000 blood pressures? int bp[ 10001 M/ declares an array of 1000 int values 5000 5002 5004 5006 bp[o] bp[1l bp[2 bp999]
6 What if you wanted to store and total 1000 blood pressures? int bp[ 1000 ] ; // declares an array of 1000 int values bp[0] bp[1] bp[2] . . . . bp[999] 5000 5002 5004 5006 . . .
Programming in C++ One-Dimensional Array Definition An array is a structured collection of components (called array elements), all of the same data type, given a single name, and stored in adjacent memory locations The individual components are accessed by using the array name together with an integral valued index in square brackets The index indicates the position of the component within the collection
7 One-Dimensional Array Definition An array is a structured collection of components (called array elements), all of the same data type, given a single name, and stored in adjacent memory locations. The individual components are accessed by using the array name together with an integral valued index in square brackets. The index indicates the position of the component within the collection
Difference Between Array and++ Programming in C Struct or class o As array is a structure, an array differs from struct or class in two fundamental was 1. An array is a homogeneous data structure whereas structs and classes are heterogeneous types 2. A component of an array is accessed by its position in the structure, whereas a component of a struct or class is accessed by an identifie
8 Difference Between Array and Struct or class ❖As array is a structure, an array differs from struct or class in two fundamental was: 1. An array is a homogeneous data structure,whereas structs and classes are heterogeneous types. 2. A component of an array is accessed by its position in the structure, whereas a component of a struct or class is accessed by an identifier
Programming in C++ Another Example o Declare an array called temps which will hold up to 5 individual float values number of elements in the array float temps 5]; //declaration allocates memory Base Address 7000 7004 7008 7012 7016 tem ps[o temps[1] temps[2 temps[3 temps[41 indexes or subscripts 9
9 Another Example ❖Declare an array called temps which will hold up to 5 individual float values. float temps[5]; // declaration allocates memory temps[0] temps[1] temps[2] temps[3] temps[4] 7000 7004 7008 7012 7016 number of elements in the array indexes or subscripts Base Address
Programming in C++ Declaration of an Array oo the index is also called the subscript o in C++, the first array element always has subscript 0. The second array element has subscript 1, etc the base address of an array is its beginning address in memory SYNTAX Data Type ArrayName [ConstIntExpression 10
10 Declaration of an Array ❖the index is also called the subscript ❖in C++, the first array element always has subscript 0. The second array element has subscript 1, etc. ❖the base address of an array is its beginning address in memory SYNTAX DataType ArrayName [ConstIntExpression];