Test 1 Flashcards
Size of char in bytes
One
Size of short in bytes
Two
Size of float in bytes
Four
Size of long in bytes
Four
Size of double in bytes
Eight
&
Address operator: accesses the variables memory location
Which byte of a variable contains the memory address?
The first one
By default, memory addresses print in what number type?
Hexadecimal
How to print an address in decimal
cout
A value that represents or holds the value of a memory location is
A pointer
Indirection operator
*
Declaration of a pointer
int ptr OR int ptr
To access the value of a variable using a pointer
ptr (ptr = 100; or cout
“*” can be used for
Multiplication, declaration of a pointer, and as the indirection operator (they’re not the same!!!)
Pointer notation
*(arrayName+1)
Array notation
Ptr[1]
How does pointer arithmetic work
It adds not 1 value, but one “amount of bytes” required for the type
Value to specify that a pointer is not being used/doesn’t point to a valid address
0
A pointer pointing to 0 is called a
NULL pointer
Use a pointer with cin
Cin»_space; *ptr;
A int *const ptr is:
A pointer whose address can’t change.
A pointer TO a const:
Can’t change the value at its memory location, but it’s memory address can change
To delete a dynamically allocated array:
Delete [] ptr;
Pointers that point to memory that has already been delete(d)
Dangling pointer
To write a function that returns a pointer:
Int *myFunct(){
Blah
Blah
Blah
return myPtr; }
Point to class members:
(*ptr).length = 5;
OR ptr->length = 5
What is -> called
Structure pointer operator
Friend functions:
Are functions from other classes that can access this classes private members
Class aggregation occurs when:
An object of one class owns an object of another class
Class composition is:
A form of aggregation where the owner class controls the lifetime of the objects of the owned class
Is-a relationship:
Inheritance
declaration:
Provides info about the existence/type of a var/function
Definition:
Provides all the information contained in a declaration, and in addition, causes memory to be allocated for the var or function
Static member vars must be declared:
Inside the class definition
Static members must be defined:
Somewhere outside of the class definition