首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于数组赋初值的有关问题

2012-02-16 
关于数组赋初值的问题typeTAxisType array[0..9] of IntegerPAxisType ^TAxisType第一种方式:vartpA

关于数组赋初值的问题
type
  TAxisType = array[0..9] of Integer;  
  PAxisType = ^TAxisType;

第一种方式:
var
  tpAxisTypeArr: TAxisType;  

begin
  for i := 0 to 9 do 
  tpAxisTypeArr[i] := 0;
end;
获得通过!



第二种方式:
var
  tpAxisTypeArr: PAxisType;

begin
  FillChar(tpAxisTypeArr^, SizeOf(tpAxisTypeArr^), 0);
end;

报错:
  [Warning] WimDev_ULTRAMAN.dpr(272): Variable 'tpAxisTypeArr' might not have been initialized


我记得Dephi中,指针就是这么赋初值的呀,为什么会报没有初始化呢?

[解决办法]
New(tpAxisTypeArr) ...
[解决办法]
既然定义为指针类型,就要先分配内存
[解决办法]
tpAxisTypeArr是数组的指针的指针,
new可以为指针内的指针类型申请空间
fillchar不会
[解决办法]
来晚了.都答完了.

热点排行