当前位置:网站首页>[2. Basics of Delphi grammar] 3 Object Pascal constants and variables
[2. Basics of Delphi grammar] 3 Object Pascal constants and variables
2022-07-02 15:42:00 【Janeb1018】
3.Object Pascal Constants and variables
3.1 Constant
stay Object Pascal in , A constant is an amount whose value cannot be changed during the execution of a program , Have certain data types . The representation of constants :
Direct constants : Constant values
declare constant : Denote with a declared identifier , Include : Symbolic constant 、 Type constant
3.1.1 Direct constants
Direct constants are constants used directly in programs .
integer constants
Such as :10、-3、0、1、2 etc.
Real constant
Fixed point real number , Number in decimal form , Such as :0.06、3.14、-2.58、0.0 etc.
Floating point real , A number expressed in scientific notation , Such as :1.234E-4 Express 1.234 ride 10 Negative 4 Power ;, -3.546E12 Express -3.546 ride 10 Of 12 Power .
Character type constants
A single character enclosed in single quotes . Such as :'d'、'E'、'2'、'=' etc. .
String constant
A string enclosed in single quotation marks . Such as :'Hello world.'、' Hello '、'3.1415926' etc. .
Boolean constants
True and False
3.1.2 declare constant
1. Symbolic constant
Declare the constants represented by the defined identifier in advance , Also known as pure constants . Define the syntax of symbolic constants :
Const < Constant names 1> = < Constant values 1>; < Constant names 2> = < Constant values 2>; ...... < Constant names n> = < Constant values n>;
Const The keyword is used to declare constants .
Object Pascal Judge the type of constant according to the value of constant . Once a constant is declared , Can be quoted .
Code example :
Const PI = 3.1415926; Msg = 'Out of memory'; ErrMsg = 'Error:' + Msg + '.';
2. Type constant
Type constants cannot appear in constant expressions . Syntax for declaring type constants :
Const < Type constant name >:< type > = < Constant values >;
Code example :
Const PI:real = 3.1415926; EnterKey:char = #13; Heading:String = 'Hello world';
3.2 Variable
A variable is an amount that can change its value when a program is running , In order to represent and reference variables, variables must be named with identifiers , And call this identifier variable name . All variables must follow the rule of declaration before reference .
1. Declaration of variables
stay Object Pascal in , Variables in unit 、 The declaration part of a function or procedure , The location of a declared variable determines its scope . Syntax format of variable declaration :
Var < Variable name 1>: < Type name 1> < Variable name 2>: < Type name 2> ...... < Variable name n>: < Type name n>
When multiple variables have the same type , Compact formats can also be used :
Var < Variable name 1>, < Variable name 2>, ......, < Variable name n>: < Type name >
among ,Var Keyword is used to declare variables , When declaring variables in a compact format , Variable names are separated by commas .
Code example :
Var a,b,c: Integer; x,y,z: Real; ch: Char; city: String;
When variables are declared , Except to conform to Object Pascal Beyond the language , Try to use meaningful names that are easy to remember and read as variable names .
2. Use of variables
Once declared, variables can be used in programs , Generally, you can assign values to variables through assignment statements , Then use variables in expressions .
Object Pascal It's a compiled language , The program can only run after compilation . When the program is compiled , The compiler will allocate memory space to variables according to their types , But the compiler does not automatically initialize variables , The value of an uninitialized variable is an uncertain random value , therefore , After variable declaration , It should be initialized in time .
The easiest way to initialize variables is to assign values to variables .
边栏推荐
- Leetcode skimming -- sum of two integers 371 medium
- 已知两种遍历序列构造二叉树
- List of sergeant schools
- 03. Preliminary use of golang
- Solve the problem of frequent interruption of mobaxterm remote connection
- 【LeetCode】344-反转字符串
- 2303. 计算应缴税款总额
- 高考录取分数线爬虫
- Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
- [leetcode] 977 - carré du tableau ordonné
猜你喜欢
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
4. Jctree related knowledge learning
Build your own semantic segmentation platform deeplabv3+
PTA 天梯赛习题集 L2-001 城市间紧急救援
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
【LeetCode】1905-统计子岛屿
LeetCode刷题——两整数之和#371#Medium
Basic knowledge of cryptography
Engineer evaluation | rk3568 development board hands-on test
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
随机推荐
Loss function and positive and negative sample allocation: Yolo series
SQL修改语句
floyed「建议收藏」
Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)
6091. 划分数组使最大差为 K
【LeetCode】417-太平洋大西洋水流问题
SQL FOREIGN KEY
Force deduction solution summarizes the lucky numbers in 1380 matrix
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
动态规划入门二(5.647.62)
2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
怎样从微信返回的json字符串中截取某个key的值?
Leetcode question brushing - parity linked list 328 medium
解决BASE64Encoder报错的问题
beforeEach
/bin/ld: 找不到 -lssl
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
03. Preliminary use of golang
【LeetCode】577-反转字符串中的单词 III
Steps for Navicat to create a new database