能力值:
( LV2,RANK:10 )
|
-
-
[讨论]动态内存每次申请的地址都是一样的,这是为什么?
我试验了一下。把程序放到桌面和放到E盘运行。分配的地址都是不一样的。但每次运行申请的地址都是一样的。没办法 ,只有改成下面程序了。用随机数打乱
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
int hit;
srand(GetTickCount());
int i;
for( i=rand(); i != 0; i-- )
malloc(4);
int *blood = (int*) malloc( sizeof(int));
*blood = 100;
printf( "当前血量:\n%d", *blood );
while(1)
{
printf( "\n输入攻击数值:");
scanf( "%d",&hit );
printf( "当前血量:\n%d", *blood -= hit );
}
free(blood);
return 0;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
|