当前位置:网站首页>How many ways can you assign initial values to a two-dimensional array?
How many ways can you assign initial values to a two-dimensional array?
2022-07-25 14:45:00 【Hua Weiyun】
How many ways can you assign initial values to a two-dimensional array
@TOC
Method 1
- Branch to initial value of two-dimensional array :
int arr[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};This assignment method is simple and intuitive , Give the value of the first curly bracket to the first line , One analogy .
ask :arr[2][0]=?
answer :9
Method 2
- Assign values to the elements in the order of the array :
int arr[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};shortcoming : If there's more data , Easy to miss , Inconvenient to check .
ask :arr[1][2]=?
answer :7
Method 3
- Assign values to some elements
int arr[3][4]={{1},{5},{9}}; The element without initial value is... By default 0.
advantage : It is applicable to the situation with more data and more zeros , There is no need to mark every zero , Just input a small amount of data .
ask :arr[2][3]=?
answer :0
Method four
- When assigning initial values to all elements , The length of the first dimension can be omitted , The system will judge the length of the second dimension according to the total number of data , But the length of the second dimension cannot be omitted .
int arr[][4]={1,2,3,4,5,6,7,8,9,10,11,12}The system will allocate storage space according to the total number of data , altogether 12 Data , Each row 4 Column , Of course, it can be determined as 3 That's ok .
ask :arr[2][2]=?
answer :11
Method five
- When assigning initial values to some elements , The length of one dimension can also be omitted , But the initial value needs to be assigned to the branch .
int arr[][4]={{1,2,3,4},{},{9,10,11,12}}; ask :arr[1][2]=?
answer :0
边栏推荐
- Why do China Construction and China Railway need this certificate? What is the reason?
- 27 选择器的分类
- 应用实践:Paddle分类模型大集成者[PaddleHub、Finetune、prompt]
- Awk from entry to earth (24) extract the IP of the instruction network card
- 【cartographer_ros】八: 官方Demo参数配置和效果
- Is it safe for Guolian securities to buy shares and open an account?
- 关于ROS2安装connext RMW的进度条卡在13%问题的解决办法
- 元器件采购系统的主要功能,数字化采购助力元器件企业飞速发展
- How to design a high concurrency system?
- [eloquence] negotiation persuasion skills and Strategies
猜你喜欢

Products on Apple's official website can save 600 yuan by buying iPhone 13 Pro max at a discount

Gameframework making games (II) making UI interface

云安全技术发展综述

Keys and scan based on redis delete keys with TTL -1
![Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]](/img/b6/62a346174bfa63fe352f9ef7596bfc.png)
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]

EDA chip design solution based on AMD epyc server

43 盒子模型

直播课堂系统05-后台管理系统

39 简洁版小米侧边栏练习

I2C device driver hierarchy
随机推荐
D2. picking carrots (hard version) (one question per day)
【cartographer_ros】八: 官方Demo参数配置和效果
基于浏览器的分屏阅读
39 简洁版小米侧边栏练习
微信公众号正式环境上线部署,第三方公众平台接入
Flask SSTI injection learning
filters获取data中的数据;filters使用data中的数据
C language and SQL Server database technology
Is it safe for Guolian securities to buy shares and open an account?
Quickly set up dobbo demo
LeetCode-198-打家劫舍
Live classroom system 05 background management system
Gateway 网关报错 SERVICE_UNAVAILABLE
Thymeleaf setting disabled
PHP 通过原生CURL实现非阻塞(并发)请求模式
OverTheWire-Bandit
Development of uni app offline ID card identification plug-in based on paddleocr
jqgrid全选取消单行点击取消事件
MySQL 45讲 | 06 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
疫情之下,生物医药行业或将迎来突破性发展