malloc calloc realloc free
malloc
#include
using namespace std;
int main()
{
int n;
printf("Enter size of array/n");
scanf("%d",&n);
int* A = (int*)malloc(n*sizeof(int));
for(int i = 0; i < n; i++)
A[i] = i + 1;
for(int i = 0; i < n; i++)
printf("%d ",A[i]);
return 0;
}
calloc
#include
using namespace std;
int main()
{
int n;
printf("Enter size of array/n");
scanf("%d",&n);
int* A = (int*)calloc(n, sizeof(int));//calloc 初始化初始值为0,而 malloc
共有 0 条评论