CSC305 Chapter 2 (Part 2)
CSC305 Chapter 2 (Part 2)
Language
Design
Principles
(part 2)
Topics
Formal parameter – the names by which passed value are referred to within subroutines
Variables
• Programmers often think of variables as names for memory locations, but there is
much more to a variable than just a name.
• A variable can be characterized as a tuple of attributes:
1. Name: any names (except reserved words) that we can declare as a variable.
2. Address: a memory address, or storage location where the actual location for a particular
variable in memory
3. Value: the value that associate with the variable and stores in the particular memory
location
4. Type: determines the type of variable (eg: int, character, string, the particular range of
value, etc)
5. Lifetime: variable life time determines how long the variable life time before it is destroyed
6. Scope: defines the capacity of variables to be accessed within a program segment (eg:
local and global variables)
Data Types
• Defines the collection of data values and the set of predefined operations on those values
• Can be classified into two :
Built in data types User define data type
Primitive data type – 4 main types: int, real Enumeration Type, Subrange Type, Object
(float), Boolean, character Type
A name as a
An integer data variable A value
type associated to a
int n = 5 variable
This data type has a location in a main memory that can be bound either statically or
dynamically
Binding
• Early binding
Advantage Disadvantage
Less costly Reduced
programmer
flexibility
• Example:
Compiler will report an error if operator is applied to incompatible operand.