lec03

lec03 - Pointers CS 2022 Introduction to C Instructor...

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

View Full Document Right Arrow Icon
Pointers CS 2022: Introduction to C Instructor: Hussam Abu-Libdeh Cornell University (based on slides by Saikat Guha) Fall 2009, Lecture 3 Pointers CS 2022, Fall 2009, Lecture 3
Image of page 1

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

View Full Document Right Arrow Icon
Pointer Pointer A pointer is just another variable that points to another variable. A pointer contains the memory address of the variable it points to. int i; // Integer int *p; // Pointer to integer int **m; // Pointer to int pointer p = &i; // p now points to i printf("%p", p); // address of i (in p) m = &p; // m now points to p printf("%p", m); // address of p (in m) Pointers CS 2022, Fall 2009, Lecture 3
Image of page 2
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 3

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

View Full Document Right Arrow Icon
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 4
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 5

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

View Full Document Right Arrow Icon
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 6
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 7

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

View Full Document Right Arrow Icon
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 8
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 9

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

View Full Document Right Arrow Icon
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Image of page 10
swap1.c: Swap #include <stdio.h> int main() { int a, b; int *p, *q; a = 10; b = 20; p = &a; q = &b; printf("Before: %d, %d, %d, %d", a, b, *p, *q); __ = __; __ = __; printf("After: %d, %d, %d, %d", a, b, *p, *q); return 0; } Before: 10, 20, 10, 20 After: 10, 20, 20, 10 Pointers CS 2022, Fall 2009, Lecture 3
Image of page 11

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

View Full Document Right Arrow Icon
swap2.c: Swap
Image of page 12
Image of page 13
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