当前位置:网站首页>[C language - zero foundation lesson 10] adventure of array Kingdom
[C language - zero foundation lesson 10] adventure of array Kingdom
2022-07-27 09:15:00 【Super Daxiong】
Preface
Blogger :Super Daxiong ( A cute new blogger )
C Language column :0 Basic science C Language column
LeetCode special column :LeetCode special column
This issue is about the adventures of array Kingdom , If there is any mistake, please point out thank you !
Recommend one to my friends Study 、 Brush problem Website ?
Various Interview questions have everything that one expects to find , Brush questions until you feel soft !
All kinds of Internet Learning materials , The real interview questions of major factories start from Start learning from scratch , Help you cope easily Various interview questions , Come and enrich yourself !
Catalog
A reference to a one-dimensional array
Initialization of one dimensional array
A reference to a one-dimensional array
A reference to a two-dimensional array
What is an array ?
I've been learning for such a long time C Have you ever thought about a question if I want to store each student's grade in a variable , How should we store data? Before we learn numbers, I believe we should set variables to store data . If there are 10 One student is using ten variables , It doesn't seem like much , It's not hard to define ten variables . If it is 1000 A student , You think the definition 1000 Is it hard for one variable ? Of course it's hard . So we introduced an array that can store multiple same data types .
Array is to define a variable and set its length to store multiple data , Reference subscripts can be stored .
Arrays can be divided into One dimensional array and multi-dimensional array , And what we use most is One dimensional array and two dimensional array .
Be careful : Array subscript from 0 Start
One dimensional array
The definition of one-dimensional array :
One dimensional arrays are defined as : Type specifier Array name 【 Constant expression 】;
int arr[10];Error model
int arr[10.5];int a=10;
int arr[a];Be careful :
- Array definition , To specify the number of elements of the array , Constant expressions in square brackets are used to indicate the number of elements , That is, array length .
- Constant expressions can include constants and symbolic constants , Can't contain variables .
A reference to a one-dimensional array
Array must be defined before using .C The language specifies that only array elements can be referenced one by one , You cannot reference the entire array at once .
The representation of array elements is : Array name [ Subscript ]
int arr[]={0,1,2};
printf("%d\n",arr[1]);result 1
Initialization of one dimensional array
example 1:
int arr[3];
arr[0]=0;
arr[1]=1;
arr[2]=2;example 2:
int arr[4]={1,2};example 3:
int arr[]={1,2,3};A reference to a one-dimensional array
Find the smallest number in the array
#include<stdio.h>
int main(){
int arr[4]={6,5,1,0};
int max=arr[0];
for(int i=0;i<4;i++){
if(max<arr[i])
max=arr[i];
}
printf("%d\n",max);
}Two dimensional array
The general form of the definition of a two-dimensional array is :
Type specifier Array name [ Constant expression ][ Constant expression ]
int arr[3][3];A reference to a two-dimensional array
Two dimensional array elements are represented as : Array name [][]
With arr[3][3] As an example
We can quote
arr[0][0] arr[0][1] arr[0][2]
arr[1][0] arr[1][2] arr[1][2]
arr[2][0] arr[2][2] arr[2][2]
Initialization of 2D array
example 1:
int arr[2][2]={
{1,2},{2,2}};arr[0][0] be equal to 1 arr[0][1] be equal to 2
arr[1][0] be equal to 2 arr[1][1] be equal to 2
example 2:
int arr[2][2]={1,2,2,2};arr[0][0] be equal to 1 arr[0][1] be equal to 2
arr[1][0] be equal to 2 arr[1][1] be equal to 2
example 3:
int arr[2][2]={
{1},{2}};arr[0][0] be equal to 1 arr[0][1] be equal to 0
arr[1][0] be equal to 2 arr[1][1] be equal to 0
example 4:
int arr[][2]={1,2,3};arr[0,0] be equal to 0 arr[1,1] be equal to 1
arr[1,0] be equal to 3 arr[1,1] be equal to 0
Be careful
Two dimensional arrays cannot omit row subscripts , But the column subscript cannot be omitted .
If there is no assignment, neither row nor column can be omitted
Arrays can be assigned fewer values, but not more
Recommend one to my friends Study 、 Brush problem Website ?
Various Interview questions have everything that one expects to find , Brush questions until you feel soft !
All kinds of Internet Learning materials , The real interview questions of major factories start from Start learning from scratch , Help you cope easily Various interview questions , Come and enrich yourself !
边栏推荐
- 巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
- 被三星和台积电挤压的Intel终放下身段,为中国芯片定制芯片工艺
- 【每日算法Day 96】腾讯面试题:合并两个有序数组
- 500 error reporting
- The execution sequence of async/await, macro tasks and micro tasks
- Thermal renewal and its principle
- 500报错
- Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
- Huawei machine test question: Martian computing JS
- Wechat applet 5 - foundation strengthening (not finished)
猜你喜欢

基于restful页面数据交互

CUDA programming-05: flows and events

Deep understanding of Kalman filter (2): one dimensional Kalman filter

Restful

Unity3d 2021 software installation package download and installation tutorial

JS call and apply

Linux Installation and remote connection MySQL records

Intel, squeezed by Samsung and TSMC, finally put down its body to customize chip technology for Chinese chips
![Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1](/img/1c/c1c1b15e502ee901a396840c01e84d.png)
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1

Cross domain and processing cross domain
随机推荐
Test picture
Primary function t1744963 character writing
Explicit animation in arkui
< script> detailed explanation of label content
Detailed explanation of two methods of Sqlalchemy
Music experience ceiling! Emotional design details of 14 Netease cloud music
openharmony萌新贡献指南
STL container - basic operation of queue and deque
Interface test tool - JMeter pressure test use
CUDA programming-01: build CUDA Programming Environment
【云驻共创】华为云:全栈技术创新,深耕数字化,引领云原生
Mangodb simple to use
BOM的常用操作和有关获取页面/窗口高度、宽度及滚动的兼容性写法
npm install报错 强制安装
A survey of robust lidar based 3D object detection methods for autonomous driving paper notes
基于ArkUI eTS开发的坚果食谱(NutRecipes
CUDA programming-05: flows and events
js call和apply
DNS domain name space
The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?