07MoreFunctionsSmall

07MoreFunctionsSmall - contents s scanf(%d,&a);...

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

View Full Document Right Arrow Icon
1 CMSC 106 Lecture Set #7 Set Started: Monday, October 10, 2011 Function Philosophy s Tracing with the Call Stack s Modularity s Encapsulation s Reusability s Modifiability Parameter Passing Details s Parameters must match in position and type s except automatic promotion is allowed s if there is a mismatch – compilation error s void f1(float x, y); s y is an integer type parameter by default s bad style s All arguments are passed by value
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Introduction to Scope s local variables s are declared within a pair of curly braces s are only available from the time they are declared until the end of those curly braces s parameters s are initialized by their corresponding argument (get a copy of that value) s are only available in the function for which they are a parameter Swapping values example s void swap1(int, int); s void swap2(int*, int*); s void swap3(int*, int*); Passing a Reference s address = reference = where it is located in memory s & s before variable name indicates its address rather than its
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: contents s scanf(%d,&a); s * s after a type name in a declaration, it means it is storing an address to something of that type s int *p; s before a variable name in lines that are not declarations of variables, it means to follow that pointer as a map to find the actual variable s printf(%d\n,*p); 3 Variables: Scoping Rules and Storage Classes s Scopes s Where the variable is visible s Options s local scope s global scope/file scope s Storage Classes s Where and how long the variable remains in existence s Options s automatic s register s static s extern Random Number Generation s provided in <stdlib.h> s function: rand s function: srand s constant: RAND_MAX s teminolody: random, pseudorandom, seed s function provided in <time.h> s time Character input and output s in <stdio.h> s function: getchar s function: putchar s constant: EOF s Using them in Loops...
View Full Document

Page1 / 3

07MoreFunctionsSmall - contents s scanf(%d,&a);...

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