当前位置:网站首页>[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 !
边栏推荐
- SQL exercise set
- DNS域名空间
- Babbitt | yuan universe daily must read: Guangzhou Nansha released the "Yuan universe nine" measures, and the platform can obtain up to 200million yuan of financial support
- 微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大?
- 博客怎么上传动态gif图
- Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
- D3.v3.js data visualization -- pictures and tips of force oriented diagram
- How to optimize the deep learning model to improve the reasoning speed
- ES6 new - string part
- ArkUI框架中的两个小技巧
猜你喜欢

罗克韦尔AB PLC 通过RSLinx Classic与PLC建立通信的具体方法步骤

C# 窗体应用常用基础控件讲解(适合萌新)

Solve the problem of Chinese garbled code on the jupyter console

Antdesign a-modal自定义指令实现拖拽放大缩小

Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic

Rewrite the tensorrt version deployment code of yolox
![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

Deep understanding of Kalman filter (1): background knowledge

【ACL2020】一种新颖的成分句法树序列化方法

pollFirst(),pollLast(),peekFirst(),peekLast()
随机推荐
ES6 new - deconstruction assignment of array / object
Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
How to register code cloud account
8 kinds of visual transformer finishing (Part 1)
【ACL2020】一种新颖的成分句法树序列化方法
Unity3d 2021 software installation package download and installation tutorial
Ztree custom title attribute
07_ Service registration and discovery summary
DNS域名空间
[cloud native kubernetes practice] deploy the rainbow platform under the kubernetes cluster
[micro service ~sentinel] sentinel dashboard control panel
Programming style
pollFirst(),pollLast(),peekFirst(),peekLast()
Rewrite the tensorrt version deployment code of yolox
Music experience ceiling! Emotional design details of 14 Netease cloud music
openharmony萌新贡献指南
ES6 new - object part
The execution sequence of async/await, macro tasks and micro tasks
【云驻共创】华为云:全栈技术创新,深耕数字化,引领云原生
Matlab solves differential algebraic equations (DAE)