06-arrays.student - Last time tail recursion/iteration...

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

View Full Document Right Arrow Icon
Last time: tail recursion/iteration duality 1: Any tail recursive function has an equivalent iterative version 2: Proof by construction: 5 steps 3: Dependency graphs/shadow vars for solving the "order problem" Today: aggregate types * Array basics * Array pitfalls * Arrays of characters: C-strings * Pointers vs. arrays ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ So far, we've worked with two sorts of data types. The first are "atoms": types with singleton values. For example: something of type "int" holds one "integer". Something of type "char" holds one character. The second are "aggregate" types: types that hold "sets" of values, where each value is of some type. When all values have the same type, we call it a "homogeneous" aggregate, otherwise it is "heterogeneous." These are sometimes also called "container" types, because they contain other types. The two we've seen so far, in the context of project 2, are lists and trees: each holds a collection of integers. In contrast, C++ has a structure called an *array*. An array is a fixed-sized, indexed, homogeneous aggregate type (a collection of items, all of the same type.) To declare and define an array of four integers (the same size as our list above), we would say the following: int array[4]; For comparison purposes, let's also declare and define an integer, foo: int foo; The environment that we get when we do this is: +--------------------------+ | +----+ | | foo | | | | +----+ | | | | / +----+ | | / | | | | / +----+ | | / | | | | array | +----+ | | \ | | | | \ +----+ | | \ | | |
Background image of page 1

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

View Full DocumentRight Arrow Icon
| \ +----+ | +--------------------------+ Question: what are the contents of "array" after this declaration? Just as one can initialize an integer, one can also initialize the contents of an array. Since we aren't initializing one value, though, we need some sort of notation to specify a set of numbers.
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 08/25/2010 for the course EECS 280 taught by Professor Noble during the Winter '08 term at University of Michigan.

Page1 / 6

06-arrays.student - Last time tail recursion/iteration...

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