2. What is C++ Pointer
• In computer science, a pointer is a programming language object,
whose value refers to (or "points to") another value stored
elsewhere in the computer memory using its memory address.
• A pointer references a location in memory, and obtaining the value
stored at that location is known as dereferencing the pointer.
3. Why using pointer? 點解一定要用到Pointer
1. Directly access memory
1. Develop OS kernel
1. Build CPU structure
2. Read CPU status
3. Change CPU mode
4. Control multi-tasking
5. Control I/O
2. Develop driver
1. DMA
2. Control I/O
3. Manipulate OS’s data structure
4. Pointer vs variable 使用對應表
Variable Pointer
Declare int a; int *a;
Assign value a=1234; *a=1234;
Assign address &a=1234 (be careful) a=1234;
5. Pointer that points to variable
int number = 88; // An int variable with a value
int * pNumber; // Declare a pointer variable called pNumber pointing to an int (or int pointer)
pNumber = &number; // Assign the address of the variable number to pointer pNumber
int * pAnother = &number; // Declare another int pointer and init to address of the variable number
6. Linux demo
Live demo
View pointer address by GDB
View pointer data
Manipulate pointer using GDB
command