- 论坛徽章:
- 0
|
/*以下为钱能《c++程序设计教程>;>;的例子,但在机器上结果运行为-842150451,我的机器是奔4 2.0G,vc6.0. 请大家测试*/
#include "iostream.h"
#include "malloc.h"
#include "stdlib.h"
void main()
{
long int arraysize;
long int *array;
cout <<"pls input a number of array elements:\n";
cin >;>;arraysize;
if((array=(long int*)malloc(arraysize*sizeof(long int)))==NULL)
{
cout<<"can't allocate memory,terminating.\n";
exit(1);
}
{
for(long int count=0;count<arraysize;count++)
array[arraysize]=count*2;
}
{
for(long int count=0;count<arraysize;count++)
cout<<array[count]<<",";
cout<<endl;
}
free(array);
} |
|