当前位置:网站首页>[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 !
边栏推荐
- 全排列递归思路整理
- Common operations of BOM and compatible writing methods for obtaining page / window height, width and scrolling
- Programming style
- < script> detailed explanation of label content
- Matlab drawing skills and examples: stackedplot
- Interface test tool - JMeter pressure test use
- Mangodb简单使用
- flex布局 (实战小米官网)
- 巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
- 【每日算法Day 96】腾讯面试题:合并两个有序数组
猜你喜欢

PyTorch自定义CUDA算子教程与运行时间分析

ctfshow 终极考核

5G没能拉动行业发展,不仅运营商失望了,手机企业也失望了

软件测试功能测试全套常见面试题【功能测试-零基础】必备4-1

B tree

"Weilai Cup" 2022 Niuke summer multi school training camp 1

Pytorch custom CUDA operator tutorial and runtime analysis

Antdesign a-modal user-defined instruction realizes dragging and zooming in and out

Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone

PyQt5快速开发与实战 4.1 QMainWindow
随机推荐
The lifecycle of arkui development framework components
Deep understanding of Kalman filter (3): multidimensional Kalman filter
B tree
The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?
Programming style
npm和yarn 更新依赖包
The difference between computed and watch
ES6 new - string part
Summary of traversal methods
Music experience ceiling! Emotional design details of 14 Netease cloud music
Restful
HUAWEI 机试题:火星文计算 js
STL container - basic operation of queue and deque
Principle of flex:1
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
Easy language programming: allow the screen reading software to obtain the text of the label control
js call和apply
Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
[cloud native kubernetes practice] deploy the rainbow platform under the kubernetes cluster
CUDA programming-01: build CUDA Programming Environment