| 明 |
C(区分大小写) |
Delphi(不区分大小写) |
PHP(区分大小写) |
| 整型变量的定义 |
|
1
2
3
4
5
6
7
|
char a = 'a'; /* 8位有符号*/
int a=10; /* 16位有符号*/
unsigned int a = 10; /* 16位无符号*/
short a = 10; /* 16位有符号*/
unsigned short a = 10;/* 16位无符号*/
long a = 10; /* 32位有符号*/
unsigned long a = 10; /* 32位无符号*/
|
|
|
1
2
3
4
5
6
7
|
I: ShortInt; { 8位有符号}
I: Byte; { 8位无符号}
I: SmallInt; { 16位有符号}
I: Word; { 16位无符号}
I: Integer; { 32位有符号}
I: Cardinal; { 32位无符号}
I: Int64; { 64位有符号}
|
|
|
| 实型变量的定义 |
|
1
2
3
|
float a = 1.0; /* 4字节*/
double a = 1.0; /* 8字节*/
long double a = 1.0; /* 10字节*/
|
|
|
1
2
3
4
|
a: Single; { 4字节}
b: Real48; { 6字节}
c: Double; { 8字节}
d: Extended; { 10字节}
|
|
|
| 字符变量的定义 |
|
|
1
2
|
a: Char; { 1字节}
a: WideChar; { 2字节}
|
|
|
| 固定长度字符串 |
无 |
|
|
| 动态字符串 |
无 |
|
1
|
a: AnsiString;{ 一般为String}
|
|
|
| 以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)
{
/* 为真执行*/
}else{
/* 为假执行*/
};
|
|
|
1
2
3
4
5
6
|
if a = 2 then
begin
{ 为真执行}
end else begin
{ 为假执行}
end;
|
|
|
1
2
3
4
5
6
|
if ($a == 2)
{
/* 为真执行*/
}else{
/* 为假执行*/
};
|
|
| 多重判断 |
|
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; /* 跳出本次进入下一循环*/
|
|
|
1
2
|
break; /* 跳出循环*/
continue; /* 跳出本次进入下一循环*/
|
|
|
1
2
|
break; /* 跳出循环*/
continue; /* 跳出本次进入下一循环*/
|
|