delphi hello world 与c++不同的地方(1)

来源:互联网 发布:高斯 知乎 编辑:程序博客网 时间:2024/05/27 14:12

======================================================
注:本文源代码点此下载
======================================================

code

program helloworld;

{$apptype console}

begin

writeln('hello world');

end.

1,delphi有过程与函数之分,函数有返回值.

delphi的参数默认是传值,如果要传址则加上var,如

code

function myfun(thisisnotptr : integer ; var thisisptr: integer);

各参数间用分号,非逗号隔开.

2,delphi的string

delphi的string分三种:

一,是常量型string,通常表示为str : pchar = 'blah';此类string等同与c/c++中的字符串.

二,为一字符数组,比如str : string[32];此字符数组的下标从1..32共32 ,因为str[0]存放的是字符的长度,所以整个字符串的长度

为33.这也就是为什么在申明如str2 : string[256];时为出错的原因.

三,ansistring,简单的说是,分配在堆中的字符串,用户不需要维护内存,此字符串前8字节作为功能区:其中前4字节是此字符串的长度,后4

字节是此字符串的引用数,引用数为0时,此内存区由系统回收.英文原文如下:

a long-string variable is a pointer occupying four bytes of memory. when the

variable is empty—that is, when it contains a zero-length string—the pointer is nil

and the string uses no additional storage. when the variable is nonempty, it points a

dynamically allocated block of memory that contains the string value. the eight

bytes before the location contain a 32-bit length indicator and a 32-bit reference

count. this memory is allocated on the heap, but its management is entirely

automatic and requires no user code.

3,数组

delphi的数组下标可以自定,用如下形式声明:

code

var

oneline : array[1..10] of char;//one dimension

matrix : array[0..3,0..3] of integer;//two dimension


======================================================
在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
原创粉丝点击