2000为占用内存数值,单位MB,数值随便改,不为0就好
成品:见附件
源码:
[ol]#include
#include
#include
#define UNIT (1024*1024)
int main(int argc, char *argv[])
{
long long i = 0;
int size = 0;
if (argc != 2)
{
printf("请输入需要分配的内存值\n");
return 1;
}
#unsigned long int strtoul(const char *nptr, char **endptr, int base);
#unsigned long long int strtoull(const char *nptr, char **endptr,int base);
size = strtoull(argv[1], NULL, 10);#字符串转换成数字,十进制
if (size == 0)
{
printf("请输入大于0的内存值");
return 1;
}
char *buff = (char *) malloc(size * UNIT);
if (buff)
printf("已分配%dMB\n", size);
buff[0] = 1;
for (i = 1; i 复制代码