lec03

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

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

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

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

View Full Document
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
Pointers Pointers CS 2022, Fall 2009, Lecture 3

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

View Full Document
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Pointers Pointers CS 2022, Fall 2009, Lecture 3

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

View Full Document
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Pointers Pointers CS 2022, Fall 2009, Lecture 3

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

View Full Document
Pointers Pointers CS 2022, Fall 2009, Lecture 3
Pointers Pointers CS 2022, Fall 2009, Lecture 3

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

View Full Document
Pointers Pointers CS 2022, Fall 2009, Lecture 3
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

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

View Full Document
swap2.c: Swap
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern