ECS 30 Lecture Notes - Lecture 11: Memory Address, Memory Management, Array Data Structure

21 views5 pages
Wednesday, 25 April 2018
ECS 030 - Lecture 11
Pointers Continued + Start of Arrays
Pointers Usage
-The idea of accessing objects through their memory address is used in many ways:
1. Output arguments for functions
2. Arrays
3. Character strings
4. Dynamic memory allocation
5. Function pointers
-All usages will be discussed in further detail later throughout the course
Variable Swap (without pointers)
-swap() - function you can write yourself to
swap values of variables
swap() does not receive variables a and
b, but only their value
-since swap() is its own function, it
does not actually operate with the
variables themselves (a and b), but
only with their value, the variables
themselves are not altered
-meaning: the global addresses of the
variables a and b, after being plugged
into the function swap(), are not
altered or touched
-cannot swap values without
pointers
graphical representation:
1
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
Wednesday, 25 April 2018
Variable Swap (with pointers)
-Through pointers and dereferencing, swap() actually operates on a and b
if you use the * in front of the variable in the function, the function changes the true
values of the defined variables by reaching their memory address
-x and y are output parameters, with side-effects outside of function
only used as tools to point to the variables
"
2
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

The idea of accessing objects through their memory address is used in many ways: 1. All usages will be discussed in further detail later throughout the course. Swap() - function you can write yourself to swap values of variables: swap() does not receive variables a and b, but only their value. Since swap() is its own function, it does not actually operate with the variables themselves (a and b), but only with their value, the variables themselves are not altered. Meaning: the global addresses of the variables a and b, after being plugged into the function swap(), are not altered or touched. Cannot swap values without pointers: graphical representation: X and y are output parameters, with side-effects outside of function: only used as tools to point to the variables. Drawbacks: approach is not scalable, won"t work if you have 100 grades.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents