在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
只是简单的c和delphi对照,这样学的很快,笔记记得很随性,只是为了看点小代码,有帮助就看看吧,delphi 已经差不多没落了。
1.object pascal 语法
一.首先是main函数 Program first; {program name} var a:integer; {varent declare} begin {program sub} Writeln('this is nextline write'); write('this will not change line'); Readln; Readln(a); Readln; {here can del the ';'} end. {must have '.'}
二.然后是数据类型和变量的声明 (1) 整型 int ---> Integer usigned int ---> Cardinal short ---> Smallint char ---> Shortint long ---> Longint {this is depend on the compiler} int64 ---> Int64 BYTE ---> Byte (usigned) WORD ---> Word (usigned) DWORD ---> Longword (usigned) 8位 ---> Real
(2) 字符 CHAR ---> Char char ---> AnsiChar wchar ---> WideChar
(3) 字符串 char* ---> PChar int* a ---> var a:^integer a = &b ---> a = @b *a ---> a^
(4) 逻辑 BOOLEAN ---> Boolean ByteBool WordBool LongBool
(5) 运算符 / ---> div != ---> <> && ---> and % ---> mod
(6)结构体 fuck ,the type can instead of struct and enum,for example
type color=(red,white,black);
type a:Integer; name:PChar; age:Integer; end;
(7)#define you know , delphi can use const NUM=$1 to instead of #define NUM 0x1 #define LANG_NEUTRAL 0x00 ---> const LANG_NEUTRAL=$00
三、条件和循环 if xx then xxx
和
if xx then xxx {这个地方不要分号} else xxx; 上面这两种写法只能适合于单条语句,如果要写几行语句需要这样 if xx then begin xxx; xxx {在begin和end间,最后一句可以不加;} end; else begin xxx; xxx end;
case n of 1:xxx; 2,3:yyy; 4: mmm; 6..9: ccc {同理 这个地方可以不加分号} end;
while xxx do begin
end;
reapet inc(a) untill xx>10
for x:= num1 to num2 do begin
end;
四、 常用函数 int(a) 取a的整数部分 pi π的取值 random 产生0~1的随机数 random(n) 产生0~n的随机数 round(n) 求n四舍五入后的整数 trunc(n) 取小数的整数部分 inc(a,n)/inc(a) 自增,等价于 a := a+n dec.... 自减,同上
五、输入输出 Writeln(2:3) 空3格输出2 Writeln('2=',3) 输出2=3 Readln ---> getchar()
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论