lec09-pointers_supp

Lec09-pointers_supp - CSC 1111 Introduction to Computing using C Pointers(Supplements 1 Outlines Review of Pointers and Their Relationship with

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ Pointers (Supplements)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outlines Review of Pointers and Their Relationship with Arrays Array Arithmetic (Optional) Array of Pointers (Optional) Dynamic 2-D Arrays (Optional)
Background image of page 2
3 int *iptr; double *dptr; iptr stores a pointer to a value of int . dptr stores a pointer to a value of type double . On a 64-bit machine, what is the size of iptr and dptr ? i.e., how many bytes of data does each of these two pointer variables store? Both iptr and dptr store pointers, but why can't dptr be used to point to a value of type int ?
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Declaring pointer variables and Getting address of variables using ptr stores a pointer to foo (or iptr stores the address of foo ) 800 801 802 803 804 805 806 807 808 809 810 811 812 813 foo ptr 800 int foo; int *ptr = &foo;
Background image of page 4
5 Dereferencing a pointer using operator * By dereferencing a pointer (using the operator * ), we can Store a value at the corresponding memory location, or Access the value stored in the corresponding location. 800 801 802 803 804 805 806 807 808 809 810 811 812 813 foo ptr 800 int foo, *ptr; ptr = &foo; *ptr = 20; cout << *ptr;
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Pointer as base address of a 1-D array If we use a pointer variable as an array, its value (the address it stores) will be used as the base address of the array. So writing *ptr is the same as writing ptr[0] . 800 801 802 803 804 805 806 807 808 809 810 811 812 813 foo ptr 800 int foo, *ptr; ptr = &foo; cout << ptr[0]; Translated into: *(800 + 0 * 4)
Background image of page 6
7 Pointer as base address of a 1-D array Only the address stored in ptr matters Address of each array elements is calculated accordingly. Note: In this example,
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 22

Lec09-pointers_supp - CSC 1111 Introduction to Computing using C Pointers(Supplements 1 Outlines Review of Pointers and Their Relationship with

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online