8.Pointers

8.Pointers - Memory address ¡ The main memory is a...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Memory address ¡ The main memory is a collection of emory locations (or memory cells) memory locations (or memory cells). ¡ Each memory location has a unique address . … 121111 121112 ¡ Actually, we use the address of a memory cell to read/write data in that ll 121113 121114 121115 cell. ¡ Thus, every variable you declared in your C++ program has an address. 121116 121117 21118 121118 … ENGG1002A 1 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a char c; 121113 121114 121115 return 0; } 121116 121117 21118 121118 … ENGG1002A 2 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a char c; 121113 121114 121115 b return 0; } 121116 121117 21118 121118 … ENGG1002A 3 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a char c; 121113 121114 121115 b return 0; } 121116 121117 21118 c 121118 … ENGG1002A 4 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a char c; 121113 121114 121115 b Thus, the address of variable a is 121112 return 0; } 121116 121117 21118 c the address of variable b is 121115 the address of variable c is 121118 121118 … ENGG1002A 5 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a char c; cout << & a << endl; out << & b << endl; 121113 121114 121115 b cout << & b << endl; cout << & c << endl; return 0; 121116 121117 21118 c } 121118 … The address-of operator &, which can only be applied to a single variable. The value is the address of that variable. ENGG1002A 6 #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a int address char c; cout << & a << endl; out << & b << endl; 121113 121114 121115 b cout << & b << endl; cout << & c << endl; return 0; 121116 121117 21118 c } 121118 … Important: Addresses have types. • Addresses of memory cells that store int values are int address . ddresses of memory cells that store double values are ouble addresses ENGG1002A 7 • Addresses of memory cells that store double values are double addresses. • Addresses of memory cells that store char values are char addresses. #include <iostream> using namespace std; int main() { int a; double b; … 121111 121112 a int address char c; cout << & a << endl; out << & b << endl; 121113 121114 121115 b double address cout << & b << endl; cout << & c << endl; return 0; 121116 121117 21118 c } 121118 … Important: Addresses have types. • Addresses of memory cells that store int values are int address . ddresses of memory cells that store double values are ouble addresses ENGG1002A 8 • Addresses of memory cells that store double values are double addresses....
View Full Document

This note was uploaded on 01/26/2011 for the course BENG 1002 taught by Professor Dr.x during the Winter '10 term at HKU.

Page1 / 73

8.Pointers - Memory address ¡ The main memory is a...

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

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