c - 将元素插入动态分配的数组
问题描述
此代码应该在数组 a 中插入 3 个元素,该数组 a 已在函数 main 中动态分配
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *a=malloc(3*sizeof(int));
int i;
printf("enter the elements of the array");
for(i=0;i<sizeof(a)/sizeof(int);++i)
{
scanf("%d",&a[i]);
}
free(a);
return 0;
}
但它只插入一个元素并终止,而如果我在统计上定义数组 a 它工作得很好
解决方案
推荐阅读
- c# - 将 WindowsIndentity 发送到 WebService
- pandas - 在熊猫中循环以从一行创建一个数据框
- python - 如何查找给定的python导入语句是内部的还是外部的?
- docker - 从 alpine 基础镜像创建 docker 镜像时如何添加用户
- elasticsearch - elasticsearch中“LIMIT”的替代方案
- javascript - 如何从 HTML 表格生成 PDF?
- reactjs - Next.js,严格的 Typescript 和缺少/很难找到 RenderPageResult 类型
- angular - 默认情况下如何打开 ng bootstrap 下拉菜单
- c++ - Vector in an abstract class
- curl - 将 bitbucket 工件部署到下载