l12_6up - : MyString, contd : CSci 1113 C/C+ for Scientists...

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

View Full Document Right Arrow Icon
: CSci 1113 C/C++ for Scientists and Engineers Section 010 - evening class Pointers, Dynamic Arrays, Linked Lists Prof. Eric Van Wyk and Ted Kaminski Spring 2010 c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 1 / 27 MyString, cont’d : Recap I Introduced pointer type. char *str; I Comparison with fixed-size arrays. I Lets us have dynamically-sized arrays. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 2 / 27 MyString, cont’d : Memory diagram void f() { int x; int a[3]; int *b; } c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 3 / 27 MyString, cont’d : Using dynamic arrays I int a[3]; int *b; I b = new int[3]; I a[0] = 2; b[0] = 2; I delete[] b; c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 4 / 27 MyString, cont’d : Stack memory management I C++ constructs all variables that come into scope I And destructs all variables going out of scope I Simple, predictable, safe. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 5 / 27 MyString, cont’d : MyString Implementation c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 6 / 27
Background image of page 1

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

View Full DocumentRight Arrow Icon
Pointer Basics : I We’ve seen some already. I Declaration. I Allocation/deletion of arrays. I Use of arrays. I Pointers are more than dynamic arrays. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 7 / 27 Pointer Basics : I “Address of” operator. I Obtain a pointer to something that already exists. I Unlike new where we create something. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 8 / 27 Pointer Basics : * I “Dereference” operator. I Make use of what the pointer points to. I int *x = . ..; x is a pointer *x is an integer c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 9 / 27 Pointer Basics : Pointer values int *p = . ..; I p = . ..; changes where p points. I *p = . ..; changes the memory where p points, which is an integer.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 6

l12_6up - : MyString, contd : CSci 1113 C/C+ for Scientists...

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

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