10 - 10. PROGRAM ORGANIZATION Local Variables Variables...

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

View Full Document Right Arrow Icon
10. PROGRAM ORGANIZATION
Background image of page 1

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

View Full DocumentRight Arrow Icon
Local Variables • Variables declared inside a function are said to be local to that function. Example: float max(float a, float b) { float big; /* big is a local variable */ if (a > b) big = a; else big = b; return big; } • A local variable exists only when the enclosing function is executing.
Background image of page 2
Local Variables • A local variable is visible only to statements in the enclosing function. • Names of local variables can be used for other purposes in the same program.
Background image of page 3

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

View Full DocumentRight Arrow Icon
External Variables • Variables declared outside functions are said to be external (or global). • One advantage of external variables is that they can be shared by several functions: #include <stdio.h> int i; /* i is an external variable */ void print_count(void) { printf("T minus %d and counting\n", i); } int main(void) { for (i = 10; i > 0; --i) print_count(); return 0; }
Background image of page 4
External Variables • Another advantage: external variables retain their values throughout the execution of the program. • External variables should be used sparingly, for the following reasons: Making a change to an external variable (changing its type,
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

Page1 / 16

10 - 10. PROGRAM ORGANIZATION Local Variables Variables...

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

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