lec5 - CS240: Programming in C Lecture 5: Functions. Scope....

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

View Full Document Right Arrow Icon
CS240: Programming in C Lecture 5: Functions. Scope. 1 Sunday, January 23, 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Functions: Explicit declaration Declaration, definition, use, order matters. Declaration : defines the interface of a function; i.e., number and types of parameters, type of return value A C PROTOTYPE gives an explicit declaration void solve(int [], int, int); Prototypes improve safety and robustness Improved interaction with the type-checker 2 Sunday, January 23, 2011
Background image of page 2
Functions: Implicit declaration First use of a function without a preceding prototype declaration implicitly declares the function If prototype follows the first use, error will say prototype is wrong Put prototypes of function at the beginning of the source file! 3 Sunday, January 23, 2011
Background image of page 3

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

View Full DocumentRight Arrow Icon
Functions: Definition DEFINITION gives the implementation of a function int my_strlen(char s[]) { i n t i = 0 ; w h i l e (
Background image of page 4
int my_strlen(char* s) { int i = 0; while(*(s+i) != ‘\0’) ++i; return i; } 5 Sunday, January 23, 2011
Background image of page 5

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

View Full DocumentRight Arrow Icon
int i = 0; while(*(s+i) != ‘\0’) ++i; return i; } What does this signify? 5
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2012 for the course CS 240 taught by Professor Rego during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 21

lec5 - CS240: Programming in C Lecture 5: Functions. Scope....

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online