分类: LINUX
2015-08-24 15:15:49
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char*str = NULL;
/*分配内存空间*/
str = (char*)calloc(10,sizeof(char));
/*将hello写入*/
strcpy(str, "Hello");
/*显示变量内容*/
printf("String is %s\n",str);
/*释放空间*/
free(str);
return 0;
}
|
|
1
2
3
4
5
6
7
8
9
10
11
|
#include<stdio.h>
#include<stdlib.h>
int main(){
int i;
int* pn = (int*)calloc(10, sizeof(int));
for(i = 0;i < 10;i++)
printf("%d", pn[i]);
printf("\n");
free(pn);
return 0;
}
|