Tech

Raw Materials–Data, Variables, & Data Types–Notes…

Raw Materials

Data, Variables, & Data Types

The ‘materials‘ we use in programming are the data that we can manipulate.

Data is the “stuff“, the raw information, that our program manipulates.

Programs manipulate data in many ways, often depending on the type of data.

Data comes in the form of many types, and each data type has a number of operations–things that we can do to it.

So, the things that we can do, or perform on the data, depends on what type of data we have at our disposal.

Variables refer to data and (depending on the programming language) may need to be declared before being defined, or used.

Without DATA a program cannot perform any useful function!!!

  • Simple data types include: (aka Primitive Data) (the building blocks)
    • character strings
    • numbers
    • Boolean, or ‘truth’ values
  • Complex data types include: (these are really combinations of primitive types)
    • collections (aka containers or sequences) like Lists, Tuples, Dictionaries (or Hashes), Arrays (or Vectors), Stacks, Bags, Sets & Queues.
    • files
    • dates (and times)
    • user defined

There are many operators in every programming language, & part of learning a new language is becoming familiar with its data types and the operators available for those types.

The same operator (e.g.–addition or modulo) may be available for different types, but the results may not be identical, or even apparently related!

Simple (or Primitive) Data Types

(Note: C++ is a strongly typed language, this means that every value has a specific type. The meaning of a value is largely determined by its type.)

Simple, or primitive data types are the most basic type of data provided by a programming language. They are the BUILDING BLOCKS upon which all the other types are built, they very foundation of computing.

A ‘built-in type’ is a data type for which the programming language provides built-in support. In most languages, all basic data types are built-in. In addition, many languages also provide a set of complex, or composite data types.

Basic primitive types are almost always value types.

  • In programming, data types can be divided into two categories:
    • a value of value type is the actual value,
    • and a value of reference type is a reference to another value.

[Most languages do not allow the behavior or capabilities of primitive (either built-in or basic) data types to be modified by programs.]

  • Classic basic primitive types may include:
    • Character
    • Integer
    • Floating-point number
    • Fixed-point number
    • Boolean
    • Reference (aka a pointer or handle or descriptor)–a value referring to another object. The reference can be a memory address, or an index to a collection of values.
    • *Strings–some languages support text strings as a primitive (e.g., Basic), while others treat a text string as an array of characters (e.g., C).
      • Most languages enclose strings in single or double quotes. Note that “200” could be mistaken as an ‘integer’-type but is actually a ‘string’-type because it is contained in quotes!