DOC PREVIEW
TRINITY CSCI 1320 - Repetition and Recursion

This preview shows page 1-2 out of 7 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Repetition and Recursion 9 26 2007 1 Opening Discussion Do you have any questions about the quiz Let s look at some solutions to the interclass problem 2 Hierarchy of Bugs When there is something wrong with a program we call it a bug This is for historical reasons even though modern bugs are caused by the programmer not chance There are three levels of bugs Syntax errors The simplest to fix The compiler helps you Runtime errors Code compiles but crashes when you run it Tools can help you find the point where it crashes Logic errors Code compiles and runs but gives you the wrong error Hardest to find of the errors 3 Using the Debugger The compiler helps you with syntax errors but you need a different tool to help you with runtime and logic errors Printing extra debug statements is the most general technique but it is often faster to use a tool called a debugger On this system we have a debugger called gbd If you compile your program with the g option you can run your program in gdb and get extra information gdb has built in help but to get you started use run to start the program where to see a stack trace and print to see variable values 4 The Comma Operator One of the more unusual operators in C is the comma operator It is the lowest priority operator and is just used to separate other expressions It has the value of the expression on the right side So the left side has to have a side effect in order to do anything You will probably never see the comma operator used outside of a for loop even though to do so is legal Using commas in the wrong place in C can lead to very odd errors 5 The Power of Recursion We already saw how we can get repetition through recursion Of course C has loops for doing repetition and you should generally use them for basic repetition The real power of recursion comes from the fact that the stack remembers things for you A loop doesn t This also allows recursive methods to call themselves more than once A recursive method that calls itself more than once generally requires some thought to convert to a loop Let s see how we can use the memory of the stack 6 Minute Essay Why are logic errors so much harder to find than syntax or runtime errors Remember that assignment 3 is due Friday at midnight Interclass Problem Do either problem 49 or 50 on page 385 7


View Full Document

TRINITY CSCI 1320 - Repetition and Recursion

Documents in this Course
Functions

Functions

10 pages

Functions

Functions

10 pages

Graphics

Graphics

10 pages

Graphics

Graphics

11 pages

Loops

Loops

4 pages

Loops

Loops

3 pages

Strings

Strings

9 pages

Functions

Functions

10 pages

Loops

Loops

11 pages

Graphics

Graphics

11 pages

Graphics

Graphics

12 pages

Sorting

Sorting

11 pages

Sorting

Sorting

10 pages

Arrays

Arrays

10 pages

Loops

Loops

18 pages

Load more
Download Repetition and Recursion
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Repetition and Recursion and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Repetition and Recursion and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?