当前位置:网站首页>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
边栏推荐
- Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer
- Pytorch training code writing skills, dataloader, Einstein logo
- 微信公众号正式环境上线部署,第三方公众平台接入
- 直播课堂系统05-后台管理系统
- How to design a high concurrency system?
- Jmeter的随机数函数怎么用
- Writing standard of physical quantities and unit symbols
- 39 简洁版小米侧边栏练习
- (原创)自定义一个滚屏的RecyclerView
- MySQL 45 talks about | 06 global locks and table locks: Why are there so many obstacles to adding a field to a table?
猜你喜欢

The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level

阿里云安装MYSQL5.7

Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud

关于ROS2安装connext RMW的进度条卡在13%问题的解决办法

苹果官网产品打折 买iPhone 13 Pro Max 可省600元

基于浏览器的分屏阅读

006操作符简介

Realsense ROS installation configuration introduction and problem solving

06. Neural network like

Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer
随机推荐
没错,请求DNS服务器还可以使用UDP协议
Practical guide for network security emergency response technology (Qianxin)
Gateway reports an error service_ UNAVAILABLE
Spark parameter adjustment and tuning
冈萨雷斯 数字图像处理 第一章绪论
[nuxt 3] (XI) transmission & module
Realsense ROS installation configuration introduction and problem solving
物理量与单位符号的书写标准
基于浏览器的分屏阅读
阿里云技术专家邓青琳:云上跨可用区容灾和异地多活最佳实践
AS查看依赖关系和排除依赖关系的办法
结构体大小
MySQL的登陆【数据库系统】
[MySQL series] - how much do you know about the index
C language and SQL Server database technology
Sudo rosdep init error ROS installation problem solution
Go语言创始人从Google离职
Melody + realsense d435i configuration and error resolution
关于RDBMS和非RDBMS【数据库系统】
Educational Codeforces Round 132 (Rated for Div. 2) C,D+AC自动机