cplusplus:pointers_1_slides
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cplusplus:pointers_1_slides [2021/10/19 19:13] – [Pointer hardware model] mithat | cplusplus:pointers_1_slides [2021/10/19 19:29] (current) – [Example] mithat | ||
---|---|---|---|
Line 6: | Line 6: | ||
Deitel, Harvey M., and Paul J. Deitel. " | Deitel, Harvey M., and Paul J. Deitel. " | ||
Mithat Konar\\ | Mithat Konar\\ | ||
- | March 28, 2019 | + | October 19, 2021 |
===== Introduction ===== | ===== Introduction ===== | ||
Line 34: | Line 34: | ||
===== Pointer hardware model ===== | ===== Pointer hardware model ===== | ||
- | A //pointer// variable set to point to '' | + | |
+ | * A //pointer// variable set to point to '' | ||
^ Variable name ^ Memory location ^ Memory contents across all 8 bytes (64 bits) ^ | ^ Variable name ^ Memory location ^ Memory contents across all 8 bytes (64 bits) ^ | ||
- | |'' | + | |'' |
|::: | |::: | ||
|::: | |::: | ||
|::: | |::: | ||
- | The //value// of the pointer variable is the base address of another variable. | + | * The //value// of a pointer variable is the base address of another variable. |
===== Pointer visual model ===== | ===== Pointer visual model ===== | ||
Line 60: | Line 61: | ||
===== Pointer syntax basics ===== | ===== Pointer syntax basics ===== | ||
- | ===== Declaration | + | ===== Pointer declaration |
* '' | * '' | ||
* Type of data being pointed to must also be indicated. | * Type of data being pointed to must also be indicated. | ||
Line 77: | Line 78: | ||
</ | </ | ||
- | ===== Declaration | + | ===== Pointer declaration |
* You can declare more than one pointer variable at a time: | * You can declare more than one pointer variable at a time: | ||
Line 99: | Line 100: | ||
* Most environments show base addresses as [[http:// | * Most environments show base addresses as [[http:// | ||
- | ===== Assignment | + | ===== Pointer assignment |
* Declare an integer variable '' | * Declare an integer variable '' | ||
Line 110: | Line 111: | ||
{{: | {{: | ||
- | ===== Assignment | + | ===== Pointer assignment |
* Declare an integer variable '' | * Declare an integer variable '' | ||
Line 129: | Line 130: | ||
- | ===== Assignment | + | ===== Pointer assignment |
- | * Chaning | + | * Changing |
<code cpp> | <code cpp> | ||
Line 142: | Line 143: | ||
</ | </ | ||
- | ===== Initialization | + | ===== Pinter initialization |
* Local pointer variables in C++ are not automatically initialized. | * Local pointer variables in C++ are not automatically initialized. | ||
* Uninitialized pointers point to arbitrary memory. //Very dangerous.// | * Uninitialized pointers point to arbitrary memory. //Very dangerous.// | ||
Line 164: | Line 165: | ||
* '' | * '' | ||
- | ===== Pointer operators | + | ===== Operators for pointers |
- | * **address operator** ''&'' | + | * **address operator** ''&'' |
- | * **indirection** or **dereferencing operator** '' | + | * **indirection** or **dereferencing operator** '' |
===== Indirection/ | ===== Indirection/ | ||
Line 220: | Line 221: | ||
<< | << | ||
<< | << | ||
- | |||
cout << endl; | cout << endl; | ||
Line 231: | Line 231: | ||
<< | << | ||
<< | << | ||
+ | |||
return 0; | return 0; | ||
} | } | ||
</ | </ | ||
cplusplus/pointers_1_slides.txt · Last modified: 2021/10/19 19:29 by mithat