说明 | C(区分大小写) | Delphi(不区分大小写) | PHP(区分大小写) |
整型变量的定义 |
char a = 'a';/*8位有符号*/ | I: ShortInt;{8位有符号} I: Byte;{8位无符号} I: SmallInt;{16位有符号} I: Word;{16位无符号} I: Integer;{32位有符号} I: Cardinal;{32位无符号} I: Int64;{64位有符号} | $i = 10;/*变量以$开头*/ |
实型变量的定义 | float a = 1.0;/*4字节*/ double a = 1.0;/*8字节*/ long double a = 1.0;/*10字节*/ | a: Single;{4字节} b: Real48;{6字节} c: Double;{8字节} d: Extended;{10字节} | $a = 3.14; |
字符变量的定义 | char a = 'a';/*1字节*/ | a: Char;{1字节} a: WideChar;{2字节} | $a = 'a'; |
固定长度字符串 | 无 | a: ShortString; | $a = 'a'; |
动态字符串 | 无 | a: AnsiString;{一般为String} | $a = 'Hello!'; |
以NULL结束的字符串 | char a[] = "Hello!"; | a: PChar; | 无 |
1字节布尔变量 | /*任何1字节数*/ | a: Boolean; | 任何变量都可以 |
加,减,乘,浮点除 | +,-,*,/ | +,-,*,/ | +,-,*,/ |
整除 | a = 3 / 2; /*运算符两边都是整型*/ | a := a div b;{a,b都是整型} | $a = 3 / 2; |
取模 | a = a % b; | a := a mod b; | $a = $a % $b; |
赋值 | a = b; | a := b; | $a = $b; |
比较 | if (a == 12) ...; | if a = 23 then ...; | if ($a == 23) ...; |
不等于 | if (a != 23) ...; | if a <> 23 then ...; | if ($a != 23) ...; |
小于,大于,小于等于,大于等于 | <,>,<=,>= | <,>,<=,>= | <,>,<=,>= |
逻辑与 | if (a && b) ...; | if (a = 2) and (b = 3) then ...; | if ($a && $b) ...; |
逻辑或 | if (a || b) ...; | if (a = 2) or (b = 2) then ...; | if ($a || $b) ...; |
逻辑非 | if (!a) ...; | if not (a = 2) then ...; | if (!$a) ...; |
数组定义 | int a[10] = {0}; | a: array[0..10] of Integer; | $MyArray = array(1,2,3,4); |
记录类型 | typedef struct{ int i; double d; }MyRes; | Type MyRec = record i: Integer; d: Double; end; | |
指针 | int *a; | a: ^Integer; | |
判断语句 | if (a == 2) { /*为真执行*/ }else{ /*为假执行*/ }; |
if a = 2 then | if ($a == 2) { /*为真执行*/ }else{ /*为假执行*/ }; |
多重判断 | switch (expr){ case expr1: DoSomething; break; case expr2: default: exprN; } |
case Variable of | switch (expr){ case expr1: DoSomething; break; case expr2: default: exprN; } |
for循环 |
for(expr1;expr2;expr3){ | for i := 10 to 20 do begin end; for i := 20 downto 10 do begin end; |
for(expr1;expr2;expr3){ |
while循环(先判断) | while(expr1) { } | while(a = 30) do begin end; | while(expr1) { } |
while循环(后判断) | do { }while(expr1); | repeat inc(c); until c > 100; | do { }while(expr1); |
跳出循环 | break; continue; | break; continue; | break; continue |
C、Delphi和PHP的基本语法对照表
最新推荐文章于 2025-08-20 11:37:09 发布