Structures
View Code
Types
- Basic Types
- variables types that only have one section of memory dedicated to it
- These types are common in every language and hold numeric values.
- Here is the list of common basic types, in increasing memory usage:
- boolean - true or false
- char - a character
- byte - a binary value
- short integer - a small integer value, about [-255,255]
- integer - an integer value, about [-32000, 32000]
- long - a large integer value, about [-2 million, 2 million]
- floating point - a decimal value, about [-2*10^7, 2*10^7] with 3
significant digits
- double floating point - a decimal value with twice the precision of
a floating point, about [-2*10^14, 2*10^14] with 6
significant digits
- Other languages call these primitive of simple types.
- Simple Types
- a basic type that's memory is totally dedicated to a numeric value
- Complex type
- a basic type that's memory is has different sections for different values
- A bit hard to understand, but bear with. The float needs about four
bytes of memory. Three of those bytes holds a numeric value,
e.g. 123, and one byte for a significant digit,
e.g. -2. The computer interprets it like this
123*10^-2 = 1.23.
- However other types, basically non decimals, have their bytes totally
dedicated to numeric values.
- Structure Types
- types that are made of basic types and/or structured types
- These are often user defined--which you take classes to learn how to
write them--but some are so useful they are predefined like string or
array.
- Memory Type
- a type that involved memory locations of other types
- Memory types go under the guises of pointer and reference. Also each
language has different rules for how memory types are. These often
don't exist in simple languages.
- These types aren't often touched until CS2.
- There are two types of these:
- reference - refers to the actual memory location of another variable,
anything done to the reference is done to the variable
- pointer - refers to a type of memory location, e.g.
ints only
User Define Types
- Enumeration
- a simple type which defines a set of variables to have integer values
- This is like defining a set of constant integers.
- This is very useful with switch statements to process different
circumstances.
- Simple Structure
- a type which has a set of various data members, which are often accessible
with the dot notation
- Simple structures are also know as struct and type.
- These are useful for processing a small set of values associated
together, e.g. the information on a ID card
- Class
- a complex structure which has a state, i.e. data members,
which often cannot be accessed and member functions, which are often
accessed with the dot notation
- The most powerful structure, mwha mwha mwhaaaa. The data members
represent a state for the class. These are often untouchable to users.
- The status of the data members are changed by operators, which are
functions specifically associated with the class.
- Data members are also know as variable member, or instance variables.
- Member functions are also know as operators and methods.
- Again this is a powerful type which you may use, but will not create
one on your own until latter levels of computer science.
- Object
- an instance of a class
- Often classes and objects are hard to conceptualize. Other people use
the blueprint analogy, but I like this one better. A class is like the
"int" in declaring a new variable, and the object is the variable you
declare like "num".
Prev --
Back to Portal --
Next