L03_PointersArraysStrings-1

L03_PointersArraysStrings-1 - CS1372 CS1372: HELPING TO PUT...

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

View Full Document Right Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Pointers, Arrays, Strings A First Look
Background image of page 1

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

View Full DocumentRight Arrow Icon
Pointers are like jumps, leading wildly from one part of the data structure to another. Their introduction into high- level languages has been a step backwards from which we may never recover. Tony Hoare Famous British computer scientist Inventor of QuickSort
Background image of page 2
Pointers are cool! Jim Greenlee Famous American computer scientist
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Recall Variable Symbolic name (representing an address) Value What kinds of things are stored in variables?
Background image of page 4
CS1372: HELPING TO PUT THE COMPUTING IN ECE So far int char strings (really just null terminated sequences of chars) Mentioned: Floating point, sound, video, etc.
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE What about Addresses?
Background image of page 6
CS1372: HELPING TO PUT THE COMPUTING IN ECE Terms A Pointer is an Address A Pointer (Variable) is an Address (Variable)
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers int i; int *ip; Pointer: Variable that contains address of another variable. A pointer is a data object which is separate from what it points to. ip is a pointer to an integer It is not necessarily pointing to an integer
Background image of page 8
CS1372: HELPING TO PUT THE COMPUTING IN ECE The Mysterious * Declaration int *ip; The name of the variable being declared is ip Per K & R meaning is that when ip gets dereferenced i.e. *ip, the item referred to is an int. Use ip is the value of the pointer *ip is the value of what it is pointing at. Here the * is an operator
Background image of page 9

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

View Full DocumentRight Arrow Icon
Question int *ip = NULL; is equivalent to? Choice 1 int *ip; *ip = NULL; Choice 2 int *ip; ip = NULL;
Background image of page 10
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i Code int i;
Background image of page 11

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i ip Code int i; int *ip;
Background image of page 12
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i 42 ip Code int i; int *ip; i = 42;
Background image of page 13

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i 42 ip Code int i; int *ip; i = 42; *ip = 84; ERROR!!! Core Dump if lucky ERROR!!! Core Dump if lucky
Background image of page 14
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i 42 ip Code int i; int *ip; i = 42; ip = &i; Address of Operator
Background image of page 15

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i 84 ip Code int i = 42; int *ip = &i; i = 42; ip = &i; *ip = 84
Background image of page 16
CS1372: HELPING TO PUT THE COMPUTING IN ECE Pointers Name Contents i ?????????? ip Code int i; int *ip; i = 42; ip = &i; *ip = &i; NO!!! NO!!!
Background image of page 17

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

View Full DocumentRight Arrow Icon
CS1372: HELPING TO PUT THE COMPUTING IN ECE Again, notice the inconsistency int i = 42; int *pi = &i; *pi = 1036; int i; int *pi; i = 42; pi = &i; *pi = 1036;
Background image of page 18
Translation! int *pi = &i;
Background image of page 19

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

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

This note was uploaded on 02/07/2012 for the course CS 1372 taught by Professor Smith during the Spring '07 term at Georgia Institute of Technology.

Page1 / 148

L03_PointersArraysStrings-1 - CS1372 CS1372: HELPING TO PUT...

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

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