This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Local variables A local variable is a variable that is declared within a method body. The program you see has two different local variables, both named temp . The syntax of a local variable declaration is: < type > < variable- name > ; and it can be an initializing declaration: < type > < variable- name > = < expression > ; The initializing declaration allows us to write a sequence of statements to swap two variables as follows: int temp= x; x= z; z= temp; We limit our remarks on local variables to the three issues that you see on your monitor: 1. When a local variable is created and destroyed. 2. The scope of a local variable. 3. Naming a local variable. When a local variable is created and destroyed Here is a call on method m , with three arguments. In executing this call, all local variables are created before execution of the method body. Note that there are two declarations for variable temp , They are different variables, and that is why you see two variables with that name. Second, the local variables remain in existence variables, and that is why you see two variables with that name....
View Full Document
This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).
- Spring '08