Presentation is loading. Please wait.

Presentation is loading. Please wait.

Brent M. Dingle Texas A&M University Chapter 5 – Section 1

Similar presentations


Presentation on theme: "Brent M. Dingle Texas A&M University Chapter 5 – Section 1"— Presentation transcript:

1 Brent M. Dingle Texas A&M University Chapter 5 – Section 1
Identifiers Brent M. Dingle Texas A&M University Chapter 5 – Section 1

2 What’s an identifier? A name used in a Pascal program is called an identifier and is defined to be any string made up of letters, digits and the underscore symbol – provided the string starts with either a letter or the underscore symbol (p. 46). Things that are identifiers: Variable names Named constants Procedure Names Some other named things that we may get to =)

3 Local Identifiers Recall that we saw local variables show up in procedures. Local variables are an example of local identifiers. A local variable is a variable declared within a procedure (or function). No statement outside the procedure (function) body may reference the local variable.

4 Other local identifiers
Recall also that procedures may have local constants and local procedures declared in their declaration section. These would be other examples of local identifiers. Again local constants and local procedures may NOT be referenced outside the body of the procedure in which they were declared.

5 A note on local procedures
Generally I would NOT recommend the usage of local procedures, however be aware that it can be done in Pascal and there may exist some scenario where it is useful.

6 If local exists Then global probably does too
As we saw previously there also exist global variables (and global constants and global procedures). These would be examples of global identifiers. Global variables are most often what is talked about in terms of global. Variables declared for the entire program are called global variables.

7 Note on global variables.
If at all possible, do NOT make any reference to any global variables within a procedure (or function). Procedures and functions should be self contained units that are meaningful outside the context of the program. See page 167 for more notes on this.

8 Formal VALUE parameters and local variables
Formal value parameters are implemented as local variables. Notice: the value of formal value parameters only changes within the body of the procedure (or function). the name of the formal value parameters only can be referenced within the body of the procedure (or function). This behavior seems a lot like a local variable’s, yes?

9 Formal VARIABLE parameters and local variables
Formal variable parameters are NOT implemented as local variables. They behave in a slightly different fashion – they allow you to alter the value of something outside the procedure.

10 Block definition A block is a program unit consisting of a parameter list, a set of declarations and the body of statements to which they apply.

11 Block example A procedure declaration consists of: the word procedure
the procedure name a parameter list (that may be empty) a set of declarations (local constants, variables, and procedures) a body of statements ending with a semicolon

12 Block example (cont) Notice that parts 3, 4, 5 are just a block, so a procedure becomes: the word procedure the procedure name a block ending with a semicolon

13 Scope All identifiers described at the start of a block are said to be local to that block or rather to have that block as their scope. The meaning given to an identifier by the parameter list or by a declaration applies ONLY within the block.

14 Suggested Exercises (not graded)
page 164, 165: 1, 2, 3, 4, 5 page 175, 176: 8, 10, 11

15 End Identifiers


Download ppt "Brent M. Dingle Texas A&M University Chapter 5 – Section 1"

Similar presentations


Ads by Google