What have we covered so far - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

What have we covered so far

Description:

Free Store (Heap) used for dynamic allocation. Memory. 0010. Dynamic Allocation of Memory in C ... part of the heap. intPointer = new int; Alternativelly: int ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 10
Provided by: nikolan
Category:
Tags: covered | far | heap

less

Transcript and Presenter's Notes

Title: What have we covered so far


1
What have we covered so far?
  • File streams in C
  • String manipulation (C strings)
  • Data Abstraction and Data Encapsulation (C
    struct and class types)
  • ADT Unsorted List
  • ADT Sorted List (inc. binary search)
  • ADT Stack
  • Introduction to C exceptions (throw and
    try-catch statements) and C templates

2
Lecture 9C Pointers
memory
address
int intPointerint anotherPointerint
oneIntPtr, twoInt
33
int alpha 8
intPointer alpha
25
is called address-of operator
intPointer 25
is called dereference operator
3
Dynamic Allocation of Memory (concept)
Dynamic Allocation is allocation of memory space
for a variable at run time (as opposed to static
allocation at compile time)
Program
Data allocated statically at compile time
Free Store (Heap) used for dynamic allocation
Memory
4
Dynamic Allocation of Memory in C
address
memory
int intPointer
intPointer new int
150
Alternativellyint intPointer new int
?
part of the heap
0150
5
Dynamic Allocation of Memory in C (more)
bool truth NULLfloat money NULL
  • We assign NULL to a pointer if we want a pointer
    to point tonothing
  • NULL is equivalent to the int value 0
  • NULL is defined in the header file ltcstdlibgt

6
Dynamic Allocation of Memory in C (more)
truth new booltruth truemoney new
float money 33.46float myMoney new float
7
Dynamic Allocation of Memory in C (more)
Pointer variables can be compared for equality
and can be assigned one to another as long as
they point to variables of the same data type.
8
Garbage Collection
delete myMoney
Note that delete does not delete the pointer
variable, but the variable (i.e. the memory) to
which the pointer points.
myMoney money
myMoney
myMoney
33.46
9
Array Names and Pointers
char alpha20char alphaPtrchar
letterPtrvoid Process(char arrayParam) alph
aPtr alphaletterPtr alpha0Process(alpha
)
Structs (classes) and Pointers
struct MoneyType int euros int
centsMoneyType moneyPtr new
MoneyTypemoneyPtr -gt euros 1000 // or
(moneyPtr).euros1000 moneyPtr -gt cents 50
Write a Comment
User Comments (0)
About PowerShow.com