当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Getting started with arfoundation tutorial 10- plane detection and placement
小白高薪捷径-Qt开发游戏—贪吃蛇
01-01-osg GL3 环境搭建
Yangyonglin, vice president of Rushi Technology: when traditional industries encounter "digital space"
365天挑战LeetCode1000题——Day 039 完全二叉树插入器 + 寻找峰值 II + 快照数组
7.3-function-templates
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
AiTalk创始人梁宇淇:镜像连接虚拟与现实的纽带
365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13
QtCreator+CMake编译器设置
随机推荐
冒泡排序 C语言
Qml类型:MouseArea
千人规模互联网公司研发效能成功之路
Visual Basic .Net 如何获取命令参数
Xiaobai high salary shortcut Qt development game Snake
EXIT中断详解
如视技术副总裁杨永林:当传统产业遇到“数字空间”
【C语言系列】—三种方法模拟实现strlen库函数的方法
C language handwritten qq-ai version
容器安全开源检测工具--问脉 VeinMind(镜像后门、恶意样本、敏感信息、弱口令等)
During the appointment, the 2022 JD cloud industrial integration new product launch was launched online
2022年SPSSPRO认证杯数学建模B题第二阶段方案及赛后总结
Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com
OCCT学习003-----MFC单文档工程
How mongodb inserts, deletes and updates documents
C语言求字符串的长度
365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13
数组学习之入门简单题 两数之和
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team