当前位置:网站首页>一维数组和二维数组的命名以及存储空间
一维数组和二维数组的命名以及存储空间
2022-08-03 05:11:00 【tt142】
一维数组
数组是类型相同的元素的集合
熟知的一维数组命名通常以 元素类型 数组名 [元素个数]构成
例如 int arr[5]={0}
这里设计一些初始化的基本常识,不再赘述
主要是区分strlen,sizeof的不同:
1,strlen只能计算字符串的长度
sizeof可以计算字符串,类型,数组等等所占空间
2,strlen计算长度不包括\0,必须要看到\0才会停止计算,但是\0不包括在内
sizeof会读取到\0,并将其算为所占空间的一部分。
3,strlen是一种库函数,需要引头文件#include<string.h>
sizeof不需要
比如下面代码的输出值是多少呢
#include <stdio.h>
#include <string.h>
int main()
{
char arr1[]="abc";
char arr2[]={'a','b','c',0};
printf("%d\n",sizeof(arr1));
printf("%d\n",sizeof(arr2));
printf("%d\n",strlen(arr1));
printf("%d\n",strlen(arr2));
return 0;
}
答案是:3 4 随机值 3
二维数组
二维数组例如 int arr[3][4]={ {1,2,3},{4,5}}
[3] 3代表这个数组有三行
[4] 4代表有四列
每一行,每一列依然是从0开始标号
{1,2,3}表示将这个二维数组看成两个三个一维数组,其中第一行也就是名字为arr[0]的一个一维数组
注意:行可以省略,但是列不可以
此外,无论一维还是二维,在内存中存储的空间都是连续的
边栏推荐
- ss-5.consul服务端+生产者+消费者
- Get the Ip tool class
- -飞机大战-
- typescript49-交叉类型
- Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
- Pr第二次培训笔记
- 设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
- Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
- Js学习笔记(四)
- CAD有生僻字如何打出来、如何提交软件相关问题或建议?
猜你喜欢
传说中可“免费白拿”的无线路由器 - 斐讯 K2 最简单刷 breed 与第三方固件教程
Kaggle(四)Scikit-learn
高可用 两地三中心
3. 无重复字符的最长子串
[Harmony OS] [ARK UI] ETS context basic operations
VSO Downloader Ultimate 5.0.1.45 中文多语免费版 在线视频下载工具
Redis常用命令
Coordinate knowledge in digital twin campus scenarios
ModelArts第二次培训
2017-06-11 Padavan 完美适配newifi mini【adbyby+SS+KP ...】youku L1 /小米mini
随机推荐
Pr第四次培训笔记
UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
Apache DolphinScheduler版本2.0.5分布式集群的安装
minio下载文件乱码或者是一条横线
[Harmony OS] [ArkUI] ets development graphics and animation drawing
Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
1230: 蜂巢
ss-4.2 多个eureka集群案例
Installation of Apache DolphinScheduler version 2.0.5 distributed cluster
VSO Downloader Ultimate 5.0.1.45 中文多语免费版 在线视频下载工具
js implements a bind function
typescript44-对象之间的类兼容器
VR全景展打造专属元宇宙观展空间
Create a tree structure
斐讯K2路由编译Padavan华硕固件和心得
3n+1问题
-飞机大战-
C-PHY速率
Djiango第四次培训笔记
求因子数量