1 / 18

Introduction to Pointers Lesson xx

Introduction to Pointers Lesson xx. Objectives. Memory setup Pointer declaration Address operator Indirection Printing addresses or pointers. Memory Setup. 10. a. (1ab). int a = 10; float x = 17.24; char c = ‘q’;. 17.24. (2fe). x. ‘q’. c. (3cd). Address . 10. a. (1ab).

gusty
Download Presentation

Introduction to Pointers Lesson xx

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to PointersLesson xx

  2. Objectives • Memory setup • Pointer declaration • Address operator • Indirection • Printing addresses or pointers

  3. Memory Setup 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; 17.24 (2fe) x ‘q’ c (3cd)

  4. Address 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; 17.24 (2fe) x ‘q’ c (3cd) 5fb

  5. Pointer Declaration 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; int *ptr; 17.24 (2fe) x ‘q’ c (3cd) ptr

  6. Address Operator & 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; cout << a; cout << &a; 17.24 (2fe) x ‘q’ c (3cd)

  7. Initializing a Pointer Variable 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; 17.24 (2fe) x ‘q’ c (3cd) 1ab ptr

  8. Different Interpretation 10 a (1ab) int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; 17.24 (2fe) x ‘q’ c (3cd) 1ab ptr

  9. Redrawing a 1ab 10 (1ab) ptr int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; 17.24 (2fe) x ‘q’ c (3cd)

  10. Sample Pointer Program #include <iostream> using std::cout; using std::endl; int main() { int y, cc = 10; int* intptr; intptr = &cc;   y = *intptr; *intptr= 32;cout << y <<* intptr << intptr <<& intptr << endl;   return 0; }

  11. Setting up Variables int y, cc = 10; int* intptr; intptr = &cc;   y = *intptr; *intptr= 32; cout << y <<* intptr << intptr <<& intptr << endl; y (1ab) 10 cc (4fe)

  12. Setting up a Pointer int y, cc = 10; int* intptr; intptr = &cc;   y = *intptr; *intptr= 32;cout << y <<*intptr << ptr <<&intptr << endl; ; y (1ab) intptr 10 cc (4fe)

  13. Initializing a Pointer int y, cc = 10; int* intptr; intptr = &cc;   y = *intptr; *intptr= 32; cout << y <<*intptr <<intptr <<&intptr << endl; y (1ab) 4fe intptr 10 cc (4fe)

  14. Indirection on the Right int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr= 32;cout << y <<* intptr << intptr <<& intptr << endl; 10 y (1ab) 4fe intptr 10 cc (4fe)

  15. Indirection on the Left int y, cc = 10; int* intptr; intptr = &cc;y = *intptr; *intptr= 32;cout << y <<*intptr << intptr <<& intptr << endl; 10 y (1ab) 4fe intptr 32 cc (4fe)

  16. Address of a Pointer Variable int y, cc = 10; int* intptr; intptr = &cc;  y = *intptr; cout << y <<*intptr <<intptr<<&intptr << endl; 10 y (1ab) 4fe intptr (55a) 32 cc (4fe)

  17. Printing Pointers int y, cc = 10; int* intptr; intptr = &cc;  y = *intptr; cout << y <<*intptr <<intptr <<&intptr << endl; 10 y (1ab) 4fe intptr (55a) 32 cc (4fe) Output 10 32 4fe 55a

  18. Summary • Memory setup • Pointer declaration • Address operator • Indirection • Printing addresses or pointers

More Related