This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 nonobvious 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.
 Spring '08
 Tuna

Click to edit the document details