csc 253

6
CSC 253 Lecture 7

Upload: terentia-avis

Post on 30-Dec-2015

27 views

Category:

Documents


0 download

DESCRIPTION

CSC 253. Lecture 7. Storage Classes. Of the following storage class modifiers, extern auto register const volatile static which are in some sense “opposites”? which of them are mutually exclusive?. static variables. Let’s write a program that demonstrates what a static variable does. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSC 253

CSC 253CSC 253

Lecture 7Lecture 7

Page 2: CSC 253

Storage ClassesStorage Classes

Of the following storage class modifiers, extern auto register const volatile static

which are in some sense “opposites”? which of them are mutually

exclusive?

Of the following storage class modifiers, extern auto register const volatile static

which are in some sense “opposites”? which of them are mutually

exclusive?

Page 3: CSC 253

static variablesstatic variables

Let’s write a program that demonstrates what a static variable does.

What are some uses of static variables?

Let’s write a program that demonstrates what a static variable does.

What are some uses of static variables?

Page 4: CSC 253

Let’s try a program with externs

Let’s try a program with externs

Declare int i in one file. Declare int j in another file. Declare one function in each of the two

files. What do we need to do to use all the

variables and functions from a single main()?

What happens if we make them static? Why?

Declare int i in one file. Declare int j in another file. Declare one function in each of the two

files. What do we need to do to use all the

variables and functions from a single main()?

What happens if we make them static? Why?

Page 5: CSC 253

Common errorsCommon errors

Let’s write programs demonstrating these … Same name, different type

this would occur if you used extern to declare a variable, but

then gave it a different type than its original declaration.

Multiple different definitions of the same function with external scope.

Let’s write programs demonstrating these … Same name, different type

this would occur if you used extern to declare a variable, but

then gave it a different type than its original declaration.

Multiple different definitions of the same function with external scope.

Page 6: CSC 253

Variable # of argumentsVariable # of arguments

Let’s write a sum function that takes a variable number of arguments.

Let’s write a sum function that takes a variable number of arguments.