使用malloc函数动态创建数组,用户输入数组大小并输出该数组
# include stdio.h # include stdlib.hint main () {int n=0; scanf_s('%d ',n ); int*ptr=(int* ) malloc ) sizeof(int ) *n ); for(intI=0; i n; I ) scanf_s('%d ',ptr[i]; //为数组中的每个元素赋值}printf ('输入的值为:'); 使用//for循环输出各要素数据for (intj=0; j n; j () printf('%d ',ptr[j] ); }返回0; }如果输入n 4,则会动态生成4个整数大小的数组,如果输入4个数据并为4个元素赋值执行,则: