lect11_Pointers

lect11_Pointers - Pointers Pointers CS CSIS1117 Computer...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Pointers SIS1117 omputer Programming CS S Co pute og a g 1 c1117 lecture 11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ontents Contents emory address Memory address Deference operator Memory access operator Accessing member functions Dynamic data ore on ointers More on pointers c1117 lecture 11 2
Background image of page 2
emory address Memory address ach ariable stored somewhere in the memory Each variable is stored somewhere in the memory. The memory address of a variable can be found sing the ddress operator using the address operator & . Memory ddress int i; char c; cout << &i << " " << &c; address 1001100 001104 i Address operator 1001104 c 1001100 1001104 c1117 lecture 11 3 Main memory
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
he ddresses re of type ointer The addresses are of type pointer . It is not of type integer !! e can declare ointer variable store the We can declare pointer variable to store the addresses of other variables . ach ointer variable ould also has it own pe Each pointer variable should also has it own type . Declare a pointer variable for storing eaddresso fanintvar iab le int x = 34; the address of an int variable. int * ptr; ptr = &x; c1117 lecture 11 4 The memory address of variable x.
Background image of page 4
Memory ddress int x = 34; ouble y = 12 3; address 000000 00001 x 34 double y = 12.3; string name("Peter"); int * ptr; .. 000001 004800 y 12.3 double * dptr; string * sptr; tr = &x; ame " eter" 004804 11324 ptr = &x; dptr = &y; sptr = &name; name Peter ptr 004800 011324 477621 477625 477629 dptr 004804 sptr 011324 ee ddress cc c1117 lecture 11 5 Main memory See address.cc
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
he ointer variables n be declared together The pointer variables can be declared together with the same type . ouble * p * q; double * p, * q; string * name, * address, * message; e can even termix ri bl nd itr We can even intermix variables and pointer variables in the same declaration . int k, * i, a, * b; It is incorrect to assign a pointer variable of one type to the address of a variable of another type nt x = 10; c1117 lecture 11 6 int x 10; char * p = &x; Error !!
Background image of page 6
ereference operator Dereference operator iven an ddress we can use the C++ ereference operator Given an address , we can use the C
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

lect11_Pointers - Pointers Pointers CS CSIS1117 Computer...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online