P.Lecture - 2.12.08 - Announcements Assignment 3 out today...

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

View Full Document Right Arrow Icon
Announcements • Assignment 3 out today – Assignment 3 and 4 logisitics •Exam 1 Thursday –55 minute exam (9:30 – 10:25) •Program Development Measurement –SLOC , person hours, logic defects pics for today Topics for today –Scope of variables xam Review 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Global (External) Variables •V a r i a b l e s declared outside functions are global •E x t e r n a l variables can be shared by several (all) functions: #include <stdio.h> int i; /* i is a global 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; } External variables retain their values throughout the execution of the program •E x t e r n a l variables should be used sparingly, if at all –I f an external variable is assigned an incorrect value, it is difficult to identify the 2 guilty function
Background image of page 2
Local Variables ariables declared inside a function are cal that function Variables declared inside a function are local to that function Example: float max(float a, float b) { oat big; /* big is a local variable */ float big; / big is a local variable / if (a > b) { big = a; } else { big = b; } turn big; return big; } •L o c a l variable exists only when the enclosing function is executing Local variable is visible only to statements in the enclosing function •N a m e s of local variables can be reused for other purposes in the me program 3 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
Parameters •A function header can contain parameter declarations void swap( int i, int j) { t temp; int temp; temp = i; i = j; = temp; j = temp; } •A variable declared as a parameter in a function header aa b e dec a ed as a pa a ete a uc to eade exists only as long as the function is executing •I
Background image of page 4
Inside of Blocks •A block of statements can contain declarations if (i < j) { t temp; int temp; temp = i; i = j; j = temp; } •A variable declared in a block exists only as long as statements in the block are executing •A variable declared in a block is visible only to statements in the block block can appear anywhere a statement is
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 03/22/2008 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 28

P.Lecture - 2.12.08 - Announcements Assignment 3 out today...

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