明 |
C(区分大小写) |
Delphi(不区分大小写) |
PHP(区分大小写) |
整型变量的定义 |
1
2
3
4
5
6
7
|
char a = 'a' ;
int a=10;
unsigned int a = 10;
short a = 10;
unsigned short a = 10;
long a = 10;
unsigned long a = 10;
|
|
1
2
3
4
5
6
7
|
I: ShortInt ;
I: Byte ;
I: SmallInt ;
I: Word ;
I: Integer ;
I: Cardinal ;
I: Int64 ;
|
|
|
实型变量的定义 |
1
2
3
|
float a = 1.0;
double a = 1.0;
long double a = 1.0;
|
|
1
2
3
4
|
a: Single ;
b: Real48 ;
c: Double ;
d: Extended ;
|
|
|
字符变量的定义 |
|
|
|
固定长度字符串 |
无 |
|
|
动态字符串 |
无 |
|
|
以NULL结束的字符串 |
|
|
无 |
1字节布尔变量 |
任何1字节数 |
|
任何变量都可以 |
加,减,乘,浮点除 |
+,-,*,/ |
+,-,*,/ |
+,-,*,/ |
整除 |
|
|
|
取模 |
|
|
|
赋值 |
|
|
|
比较 |
|
|
|
不等于 |
|
|
|
小于,大于,小于等于,大于等于 |
<,>,<=,>= |
<,>,<=,>= |
<,>,<=,>= |
逻辑与 |
|
1
|
if (a = 2 ) and (b = 3 ) then ...;
|
|
|
逻辑或 |
|
1
|
if (a = 2 ) or (b = 2 ) then ...;
|
|
|
逻辑非 |
|
|
|
数组定义 |
|
1
|
a: array [ 0..10 ] of Integer ;
|
|
1
|
$MyArray = array (1,2,3,4);
|
|
记录类型 |
1
2
3
4
|
typedef struct {
int i;
double d;
}MyRes;
|
|
1
2
3
4
5
|
Type
MyRec = record
i: Integer ;
d: Double ;
end ;
|
|
|
指针 |
|
|
|
判断语句 |
|
1
2
3
4
5
6
|
if a = 2 then
begin
end else begin
end ;
|
|
|
多重判断 |
1
2
3
4
5
6
7
8
9
10
11
12
|
switch (expr){
case expr1:
DoSomething;
break ;
case expr2:
DoSomething;
Break;
case expr3:
DoSomething;
Break;
default : exprN;
}
|
|
1
2
3
4
5
6
7
8
|
case Variable of
101 : DoSomething;
102 :
begin
end ;
103 : DoAnotherthing;
else DoTheDefault;
end ;
|
|
1
2
3
4
5
6
7
|
switch (expr){
case expr1:
DoSomething;
break ;
case expr2:
default : exprN;
}
|
|
for循环 |
1
2
3
|
for (expr1;expr2;expr3){
DoSomething;
}
|
|
1
2
3
4
5
6
7
|
for i := 10 to 20 do
begin
end ;
for i := 20 downto 10 do
begin
end ;
|
|
1
2
3
|
for (expr1;expr2;expr3){
DoSomething;
}
|
|
while循环(先判断) |
|
1
2
3
|
while (a = 30 ) do
begin
end ;
|
|
|
while循环(后判断) |
|
1
2
3
|
repeat
inc(c);
until c > 100 ;
|
|
|
跳出循环 |
|
1
2
|
break; /* 跳出循环*/
continue; /* 跳出本次进入下一循环*/
|
|
|