#include<stdio.h>#include<stdlib.h>intmain(){
int*ptr =NULL;int num;int i;printf("请输入整数个数:\n");scanf("%d",&num);ptr =(int*)malloc(num*sizeof(int));for(i =0; i < num; i++){
printf("请输入第%d个整数",i+1);scanf("%d",&ptr[i]);}printf("结果是:\n");for(i =0; i < num; i++){
printf("%d ",ptr[i]);}putchar('\n');free(ptr);return0;}
memset(初始化)
#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 10intmain(){
int*ptr =NULL;int i;ptr =(int*)malloc(N*sizeof(int));if(ptr ==NULL){
exit(1);}memset(ptr,0, N*sizeof(int));for( i =0; i < N ; i++){
printf("%d ",ptr[i]);}putchar('\n');free(ptr);return0;}