Download presentation
Presentation is loading. Please wait.
Published byRalf Hancock Modified over 9 years ago
1
1 The CONST definition CONST Pi = 3.14159, City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why not just put the value in the program? Note: The compiler automatically defines the type to the constant identifier by looking at the value assigned to it.
2
2 Reserved words Certain words have special meaning to the compiler. Therefore these words cannot be used as constant or variable identifiers. We have seen some examples: –DIV, MOD –VAR, CONST – PROGRAM, BEGIN, END
3
3 String Variables Note: This is not part of the Pascal standard. It was added to Turbo Pascal (and some other Pascal compilers) To declare a string variable we could write: –VAR Country: string[13]; To assign a value to a string variable we could write: –Country := ‘United States’;
4
4 More about integers What if you need an integer larger than 32767? –Using integer type would be incorrect –another type called LongInt is used -2147483648 -> 2147483647 other integer types are: –byte (0->255) –shortint (-128->127) –word (0->65535)
5
5 More about reals Reals also have other types –real6 bytes11 to 12 digits –single4 bytes7 to 8 digits –double8 bytes15 to 16 digits –extended10 bytes19 to 20 digits
6
6 Chapter 3 topics write / writeln readln VAR declaration CONST definition assignment statement (including arithmetic)
7
7 Formatting output: integers Field: a group of columns in which results are printed is called a field Field width: The number of columns in the field writeln(IntId:##) –IntId is an integer identifier or value –## is the rightmost column to print the integer (Compiler will ignore this value if its smaller than number of digits) can be written as any integer expression default is one
8
8 Formatting output: reals Writeln (RealId:#1:#2) –RealId is a real identifier or value –#1 is the rightmost column to print the real –#2 is the number of digits you want on the right of the decimal point. If #2 is omitted, scientific notation is used
9
9 Formatting output: strings Writeln (stringId:##) –stringId can be a string or character identifier or value –## is the rightmost column for the string to be printed in
10
10 Formatting output: Boolean Similar to strings note: Although the compiler is not Cap sensitive, it always prints Boolean values in all CAPS.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.