C++程序题目,没看懂,这个程序不是错的吗?

#define MAX_MEM_SIZE  100

int  GetMem(int iLen, void **ppMem)

{

if (NULL == ppMem)

{

return -1;

}

if (iLen <= 0)

{

return 0;

}

else if (iLen < MAX_MEM_SIZE)

{

*ppMem = malloc(iLen);

return iLen;

}

else

{

*ppMem = malloc(MAX_MEM_SIZE);

return MAX_MEM_SIZE;

}

}


void  test()

{

char *pMyMem;

int i;

int j;

i = GetMem(i, (void **)&pMyMem);

if (NULL != pMyMem)

{

for (j=0; j<i; j++)

{

pMyMem[j] = 0;

}

}

}

A) 因为pMyMem未初始化,test函数中的GetMem可能会返回-1

B) 因为i未初始化,test函数中GetMem可能返回比MAX_MEM_SIZE大的值

C) 因为pMyMem未初始化,for循环内的赋值操作可能会导致写内存异常

D) 无论pMyMem,i,j为何值时,test函数内都不会出现写内存异常

#c##笔试题目#
全部评论

相关推荐

05-30 12:03
山西大学 C++
offer来了我跪着接:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务