您的位置:首页 > 其它

指针,static,const,引用,violate等等

2014-07-11 10:38 246 查看
#include <stdio.h>
#include <malloc.h>

int main() {
char **rlname;

//malloc!
rlname = (char**)malloc(100 * sizeof(char*) );
for (int j = 0; j < 100; j++)
{
rlname[j] = (char*) malloc(30 * sizeof(char) );
}
//free

for (int j = 0; j < 100; j++)
{
free(rlname[j]);
}
free(rlname);
}


#include <iostream>
using namespace std;
int main()
{
int m, n, **p;
cin >> m >> n;
p = new int*[m];
for (int i = 0; i < m; ++i)//for allocate memory
{
p[i] = new int
;
//*p + i = new int
;//wrong
}
//....
//Process your program;
for (int j = 0; j < m; ++j)//for free the heap memory
{
delete[]p[j];
}
delete[]p;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: