Cards (18)

  • 3 categories of data types - simple, structured, pointers.
  • A simple data type is the foundation of the structured data type, where it can store only one value at a time, in contrast with a structured data type, where it is a collection of multiple data items of the same type that are used to effiecienty organize and manipulate large amounts of data.
  • One of the structured data types, used in C++ programming called an array.
  • An array is a collection of fixed number of components (also called elements) all the same data type and in a contiguous memory location using a single variable.
  • Characteristics of an Array
    • Fixed size
    • Homogeneous data
    • Indexed access
  • Types of an Array
    • One-dimensional Array
    • Multidimensional Array
  • Types of an Array
    • One-dimensional Array
    • Multidimensional Array
  • Array Syntax: data_type array_name [array_size]
  • array_size - refers to the number of elements (container) the array can hold.
  • Properties of an Array:
    • Array have an index and always start with 0.
    • To traverse the array element always use the index operator or subscript operator symbol []
    • Array size is always constant
    • sizeof operator can be used to determine the bytes size of an array and length or the number of elements of an array
  • An array can have a partial initial value. (or yung sobra sa array size)
  • Accessing an Array components
    Syntax:
    array_name[index];
  • Index - refers to the number of which element (container) that you want to access. (always start with 0).
  • The for-each loop is also known as range-based for loop that is exclusively used to traverse an array.
  • for-each loop syntax:
    for (type variableName : arrayName){
    loop body
    }
  • In using the for-each loop, using the & symbol (reference) to manipulate directly the original memory location of the variable. Unlike without using the &, the loop will create a copy for each element and will not affect any modifications in an array.
  • Multidimensional Array Syntax:
    data_type array_name [row_size][column_size];
  • Example of multidimensional array:
    int num[3][5]; //there is a total of 15 elements of an array