C语言: 创建数组的几种方法
2023-11-16 06:34:09
创建数组有三种方法
1、声明一个数组,声明时用常量表达式指定数组维数,然后可以用数组名访问数组元素
2、声明一个变长数组,声明时用变量表达式指定数组的维数,C99支持
3、声明一个指针,调用malloc(),然后使用该指针来访问数组元素,指针为常量,不能进行运算
#include <stdio.h>
#include <stdlib.h>
int main(){
int n;
int *p;
p = (int *)malloc(n*sizeof(int));
if(scanf("%d",&n) != ){
printf("%s","exit");
exit(EXIT_FAILURE);
} int i; for(i=;i<n;i++){
printf("%d:",i);
scanf("%d",p+i);
} for(i=;i<n;i++){
printf("%d",p[i]);
}
}
最新文章
- 不使用return false阻止event默认行为
- 从零自学Hadoop(17):Hive数据导入导出,集群数据迁移下
- online_jf.lua --累计在线时间领取物品(积分)的lua脚本
- WPF控件
- [转]SQL注入攻防入门详解
- POJ 3111
- 关于dialog引起的 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView not attached to window manager 错误的分析
- android Uri获取真实路径转换成File的方法
- SQL Server 阻塞排除的 2 方法
- 1.SQL统计某张表的列数。
- 前端学习笔记(zepto或jquery)——对li标签的相关操作(五)
- hdu_5877_Weak Pair(离散+DFS+树状数组)
- 在Windows上安装MongoDB
- [NOIp 2013]货车运输
- shell中read使用
- Lambda的使用与实战
- DensePose: Dense Human Pose Estimation In The Wild(理解)
- Codeforces 1009G Allowed Letters 最大流转最小割 sosdp
- 接口测试工具-poster
- python 各种开源库