64,643
社区成员
发帖
与我相关
我的任务
分享
如下代码
int *pI = new int;
int *pII = (int *)malloc(sizeof(int));
怎么样知道pI和pII所指向的内存块的大小...
#include <iostream>
#include <malloc.h>
using namespace std;
void test()
{
int *pI = new int[10];
int *pII = (int *)malloc(sizeof(int) * 100);
cout<<(_msize(pI))<<endl;
cout<<(_msize(pII))<<endl;
delete[] pI;
free(pII);
}
int main()
{
test();
system("pause");
return 0;
}
#include <iostream>
using namespace std;
void test()
{
int *pI = new int;
int *pII = (int *)malloc(sizeof(int));
cout<<(_msize(pI))<<endl;
cout<<(_msize(pII))<<endl;
delete pI;
free(pII);
}
int main()
{
test();
system("pause");
return 0;
}
#include <iostream>
#include <malloc.h>
using namespace std;
void test()
{
int *pI = new int;
int *pII = (int *)malloc(sizeof(int));
cout<<(_msize(pI))<<endl;
cout<<(_msize(pII))<<endl;
delete pI;
delete[]pII;
}
int main()
{
test();
system("pause");
return 0;
}