C_lecture_4 - CS 11 C track lecture 4 ┬ Last week arrays ┬ This week ┬ Recursion ┬ Introduction to pointers Lab 4 ┬ Harder than previous labs ┬ One

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CS 11 C track: lecture 4 ¡ Last week: arrays ¡ This week: ¡ Recursion ¡ Introduction to pointers Lab 4 ¡ Harder than previous labs ¡ One non-obvious trick ¡ hints on web page ¡ email me if get stuck ¡ Support code supplied for you ¡ Read carefully! Recursion (1) ¡ Should be familiar from CS 1 ¡ Recursive functions call themselves ¡ Useful for problems that can be decomposed in terms of smaller versions of themselves Recursion (2) int factorial (int n) { assert(n >= 0); if (n == 0) { return 1; /* Base case. */ } else { /* Recursive step: */ return n * factorial (n - 1); } } Recursion (3) factorial (5)--> 5 * factorial (4)--> 5 * 4 * factorial (3)--> 5 * 4 * 3 * factorial (2)--> 5 * 4 * 3 * 2 * factorial (1)--> 5 * 4 * 3 * 2 * 1 * factorial (0)--> 5 * 4 * 3 * 2 * 1 * 1--> 120 Pointers (1) ¡ Address: ¡ A location in memory where data can be stored ¡ e.g. a variable or an array ¡ Address of variable x is written &x ¡ Pointer: ¡ A variable which holds an address Pointers (2) 10 0x123aa8 i name address contents int i = 10; int * j = & i; 0x123aa8 0x123aab j /* j "points" to i */ Pointers...
View Full Document

This note was uploaded on 04/30/2008 for the course C CMPE 150 taught by Professor Tuna during the Spring '08 term at Bo─čazi├ži University.

Page1 / 23

C_lecture_4 - CS 11 C track lecture 4 ┬ Last week arrays ┬ This week ┬ Recursion ┬ Introduction to pointers Lab 4 ┬ Harder than previous labs ┬ One

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