Data Types Flashcards
Be able to explain data types to someone else
How do Data Types work?
Variables use data types to restrict and tell what type of data is stored in them (during declaration).
Each one needs diff amount of memory allocated by the compiler.
What are the 7 built in/primitive data types, and what kind of data is stored in each of them?
Integer (int) = a whole number.
Characters (char) = letters/punctuation/digits.
Boolean (boo) = logical values ‘true/false’.
Floating Point (float) = decimal/single precision FP values.
Double FP (double) = same as FP, but double the bytes.
void = no value.
Wide Character (whcar_t) = same as char, but greater memory for it.
What is the operator that will show the number of bytes for each data type?
sizeof(x)
What are data type modifiers?
These can modify the length of data a built in data type can hold.
What are the 4 DATA TYPE MODIFIERS and what are they used for?
SIGNED = to explicitly indicate that the value can represent both + & - values.
UNSIGNED: variable can only have + values or 0 = increases range due to no neg values.
SHORT: reduces the size of (usually int/long) data types. ~ 2 bytes
LONG: increases size of DT, ~4-8 bytes.
What are DERIVED data types?
These are DTs that’re derived from the built-in ones, to create more complex ones.
DDT: What are ARRAYS?
A collection of elements of the same type stored together in memory.
A list where each element can be accessed using an index.
E.g. int numbers [x]
DDT: What are POINTERS?
A variable that stores the memory address of another variable.
E.g. int value = x
int* ptr = &value
DDT: How do REFERENCES work?
Akin to a nickname for another variable. Once assigned, its refers to the same memory location as the original variable.
E.g. int value = 42
int& ref = value;
UDT: Describe CLASSES and OBJECTS.
A Class is are user-defined data type, that define/present custom structures/behaviors that don’t exist as built-in types.
E.g.
struct Person {
std::string name;
int age;
};
Objects are instances of these user-defined classes. The actual “things” created from the blueprint provided by the class.
What are ABSTRACT/USER-DEFINED data types?
These are defined by the user itself, represent real world object/concepts in the program.
UDT: What are STRUCTURES?
They are used to group related variables under one name.
(struct)
E.g. struct Point {
int x, y;
};
UDT: What are ENUMERATIONS (enum)?
A UDT consisting of a set of named integral constants. It’s useful for representing a fixed set of values.
E.g. enum Days { . . . . ]