当前位置:网站首页>C language one-dimensional array
C language one-dimensional array
2022-07-29 05:27:00 【Tortilla 85】
One dimensional array
1. Definition
An array is composed of a series of elements with the same data type . You can use different data types to define arrays .
Such as :
int arr[100];// The data type is int Array of
char ch[100];// The data type is char type
double nums[100];// The data type is double type
Such as arr[100]
arr For array name
100 Is the number of array elements
**[] The value in must be constant **
2. Initialize array
Array storage


You can find that the array subscript starts from zero , The address of the array is in 4 byte (int The size of the type variable ) Continuous storage .
Array boundary
When using arrays, you should pay attention to the boundary of arrays , You must ensure that the subscript is a valid value
int arr[5]={
0};
// Among them is arr[0]=0 arr[1]=0 arr[2]=0 arr[3]=0 arr[4]=0
// The number of array elements is 5 Array index from 0 Start until the number of elements is reduced by one namely 0,1,2,3,4
Such as arr[5] Beyond the border , After running, because arr[5] Is undefined , The compiler will abort ( Using out of bounds array subscripts will cause the program to change the values of other variables ).
( But during the compilation process, the compiler generally does not check for errors , because C The principle of trusting programmers , No boundary checks
)
The array should be initialized or the number of elements should be indicated before use .
The following is the C Several methods commonly used in language to initialize arrays :
int arr[100]={
0};// Initialize its 100 The element values are 0
int arr[]={
1,2,3,4,5,6,7,8,9};// to arr 1-9 Value
int arr[5]={
0,1,2,3,4};// Given number , In the given 5 Elements
int arr[100]={
0,1,2,3,4};// after 95 The default value of elements is 0
3. Use of arrays
Assign value to element
If given arr[5] assignment 1,2,3,4,5
int arr[5];
take arr[0] Regard the data type as int A variable called arr[0]
int arr[5];
arr[0]=1;
arr[1]=2;
arr[2]=3;
arr[3]=4;
arr[4]=5;
In use, it can be combined with circulation
for(i = 0;i < 5;i++)
{
arr[i]=i;
}
边栏推荐
- EXIT中断详解
- QT学习:QDropEvent拖拽事件
- 题解:在一个排序数组中查找元素第一个和最后一个的位置 (个人笔记)
- 365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
- 167. 两数之和 II - 输入有序数组
- 为啥谷歌的内部工具不适合你?
- AI应用第一课:C语言支付宝刷脸登录
- C语言连连看秒杀辅助
- 365天挑战LeetCode1000题——Day 036 二叉树剪枝 + 子数组和排序后的区间和 + 删除最短的子数组使剩余数组有序
- QT series - Installation
猜你喜欢

osg3.6.5编译freetype失败

6.3 references

MySQL的详细安装使用教程(保姆式安装图文讲解)

51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭

Live broadcast Preview: integration of JD cloud Devops and jfrog product library

Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com

Complete ecological map of R & D Efficiency & selection of Devops tools

R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience

321,京东言犀×NLPCC 2022挑战赛开赛!

Cmu15-213 malloc lab experiment record
随机推荐
Why is Google's internal tools not suitable for you?
阿里云张新涛:异构计算为数字经济提供澎湃动力
Is Huatai Securities an AA level securities company? How about this company? Is it safe to open an account?
京东云分布式链路追踪在金融场景的最佳实践
365天挑战LeetCode1000题——Day 039 完全二叉树插入器 + 寻找峰值 II + 快照数组
Database course design of online assistant teaching platform for high school chemistry
The road to success in R & D efficiency of 1000 person Internet companies
321, Jingdong Yanxi × Nlpcc 2022 challenge starts!
最新坦克大战2022-全程开发笔记-1
webgl1.0下texture2D和texture2DProj区别
Custom QML control: imagebutton
OCCT学习002-----环境搭建
How mongodb inserts, deletes and updates documents
阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
The latest tank battle 2022 - full development notes-3
D3d Shader Instruction
副作用和序列点
京东云金秋上云特惠进行中!扫码参与活动
研发效能生态完整图谱&DevOps工具选型必看
【赛事预告】云上开发,高效智能——第二届阿里云ECS CloudBuild开发者大赛即将启动