DOC PREVIEW
TRINITY CSCI 1320 - Standard Functions and Scope

This preview shows page 1-2-3 out of 8 pages.

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

Unformatted text preview:

Standard Functions and Scope 9 12 2007 1 Opening Discussion Let s look at interclass problem solutions Why do we use functions in C How do we add functions to a C program I have set up the online grading for this semester Your username is normal and your starting password is your 7 digit TU ID number 2 Standard Functions C provides you with a large number of standard functions So far the only parts of the standard C libraries we have seen are printf and scanf Other library calls require other header files Do man on a header name to see contents math h sin cos sqrt pow etc stdlib h abs rand etc 3 Linking the Math Library If you use the math library you will need to provide an extra flag on the command line when you compile Use lm short for link math to tell the compiler to link in the math libraries 4 Scope The term scope refer to the range of a program over which a particular name can be used C basically has two types of scope global and local Global scope means that it can be used anywhere in the program Local scope means that it can only be used in the block in which it is declared All functions are in the global scope I throw people in the fountain for putting variables in the global scope Parameters are locally scoped to the function they are passed to 5 Keys to Good Functions Large problems can be decomposed in many different ways There are several simple rules of thumb you should try to follow to come up with a good decomposition Make it meaningful Remember that we decompose problems to help us deal with complexity and make the solution easier to understand This helps if the pieces have some meaning their their names should reflect that meaning Make them flexible and reusable We will spend a lot of time trying to not duplicate code Duplicated code is bad on many levels 6 Writing more Functions We are on the verge of being able to write some real programs Let s start that today by writing a program that involves several functions 7 Minute Essay What questions do you have about functions Quiz 2 is next class Interclass Problem Do problem 34 on page 225 8


View Full Document

TRINITY CSCI 1320 - Standard Functions and Scope

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 Standard Functions and Scope
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 Standard Functions and Scope 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 Standard Functions and Scope 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?