Week 6 Flashcards
These are easy and fun to learn.
Pointers
Some C++ tasks are performed more easily with ______, and other C++ tasks, such as dynamic memory allocation, cannot be performed without them. These are variables that store memory addresses.
Pointers
They allow direct memory access and manipulation, making them useful for dynamic memory allocation, arrays, and function arguments.
Pointers
It is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before you can work with it. The general form of a pointer variable declaration is
Pointers
Every variable is a memory location, which has its address defined.
Ampersand/Address-of Operator (&)
That address can be accessed using the ________________, which denotes an address in memory.
Ampersand/Address-of Operator (&)
returns the memory address of its operand.
Ampersand/Address-of Operator (&)
returns the value of the variable located at the address specified by its operand.
Dereference/ Contents-of Operator (*)
is basically an alias for the variable the pointer points to
Dereference/ Contents-of Operator (*)
There are few important operations, which we will do with the pointers very frequently.
a. We define a pointer variable.
b. Assign the address of a variable to a pointer.
c. Finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
It is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.
Reference variable
Is the process of setting aside sections of memory in a program to be used to store variables
Memory Allocation
What are the three type of memory allocation
Static Memory Allocation
Automatic Memory Allocation
Dynamic Memory Allocation
it means that the memory for your variables is allocated when the program starts.
Static Memory Allocation
the size is fixed when the program is created.
Static Memory Allocation
applies to global and static variables
Static Memory Allocation
static memory allocation uses ________as its storage of memory
Memory Stack
occurs for (non-static) variables defined inside functions and is usually stored on the memory stack.
Automatic Memory Allocation
you do not have to reserve extra memory using them, but on the other hand, have also limited control over the lifetime of this memory
Automatic Memory Allocation
Example of this is automatic variables in a function are only there until the function finishes
Automatic Memory Allocation
you know the exact size and the lifetime of these memory locations.
Dynamic Memory Allocation
if you don’t free it, you’ll run into memory leaks, which may cause your application to crash, since at some point of time, system cannot allocate more memory
Dynamic Memory Allocation
It uses Memory Heap
Dynamic Memory Allocation