{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L19pointers - Pointers What is Pointer q q q q q every...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Pointers
Image of page 1

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

View Full Document Right Arrow Icon
What is Pointer every variable has memory address char c=‘y’; int i=2; address of variable i is 0022 address can used to refer to this variable address can be stored in a variable of special type called pointer (variable) C++ provides an abstraction of pointer pointer is used only to refer to the variable it points to - we usually don’t think of pointers as holding integer (address) just a reference to a variable name memory address i ‘y’ c 2 0021 0022 0021 cp name memory address i ‘y’ c 2 0021 0022 cp
Image of page 2
Pointer Syntax pointer variable is declared as follows: type_of_variable_pointed_to *pointer_name; example: double *p; int *ip; pointer declarations can be freely intermixed with ordinary variable declarations: char *cp, c1=‘y’, c2=‘n’; int i, *ip,; pointer to a pointer is legal and sometimes used: char **cpp; pointer can be assigned value using & ( address of ) operator: cp = &c1; // until reassigned cp “points at” c the value of a variable the pointer points to can be accessed using * ( dereferencing ) operator: cout << *cp << endl; *cp = ‘G’;
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern