当前位置:网站首页>char array/string array|array pointer/pointer array/
char array/string array|array pointer/pointer array/
2022-08-02 16:02:00 【white U】
数组;
数组的类型 由
- 元素的类型
- 数量
The definition of the array determines the type of the array,The number of elements and the element type.
语法结构: 类型 数组名 [元素个数]
int Arr [10]
The number of elements must be an integer constant,且必须 >0 .
The size of the array is determined at compile time,编译系统按照定义为数组分配一段连续的存储单元.(And the size cannot be changed,So it cannot be defined as a variable,但C99标准可以)
计算数组大小:sizeof(ar)/sizeof(ar[0]);//Divide the array size by the size of the element type.is the size of the array.still occupies one byte,但是strlen()`Calculated is the length of the string,不包括.
char str[10] = {‘a’,‘b’,‘c’,‘d’,‘e’} 0的ascll码值和\0相同.因此 被视为字符串.
字符串:凡是由'\0'The end is a string
字符数组:anything'\0'The end is an array of characters.
当len = strlen(strd),
1,char strd[] = {
'a','b','c','d','e'} 值为5
2,char strd[] = {
'a','b','c','d','e','f','g','h'} 值15
明显错误,It's because it's looking for when it's computing'\0',So out of bounds,而1Knowledge is better luck,刚好等于5

Don't mention the concept of character arrays again!!Jumping to the string array is to think of the latter\0 Its length cannot be calculated,Only its size can be calculated.
- 数组名是指针,但是却丢失了数组另一个要素:数组的大小,and the number of array elements.编译器按数组定义时的大小分配内存,But the runtime does not check the bounds of the array,This can lead to unpredictable errors.
int ar[] = {1,2,3,4,5,6}
ar 代表数组首元素的地址
*ar *(ar+1) *(ar+3)···· (ar+i)
i[ar] 和 ar[]相等, are converted to pointers
为什么
Arrays as arguments to functions degenerate into pointers呢:We will analyze from time efficiency and space efficiency.
void print_Ar(int br[10]);
void print_Ar(int br[]);
void Printf(int *br , int n);
Let's first assume that arrays are used as formal parameters of functions,Let's analyze the calling process;
We don't just pass the array name to the formal parameter during the pass,Also pass the number of arrays to the formal parameter
int main()
{
int arr[10] ;
数组名arr Uninitialized means assignment,没有存储数据.
int brr[3] = {
11,22,22};
brr 已经初始化
return 0;
}
数组指针:
int *ar[5]5An array whose element type is an integer pointer
int *ar[5] = {&a,&b,&c,&d} //The undefined part is 0指针数组 :
int (*pa)[5];pa是一个指针变量,(The number of elements that can be stored is 5,The element type is an integral type)的数组的地址
边栏推荐
猜你喜欢
随机推荐
mininet hosts talk to real internet
仿真结果的格式&定制
tpproxy-tcp透明代理
net start mysql 服务名无效。
Qt | 定时器的使用 QTimer
指针/【类型】对指针加一能力的影响(&*ip ,*&ipd)
如何编辑VirtualLab Fusion结果的格式
Oauth2.0 补充
极简式 Unity 获取 bilibili 直播弹幕、SC、上舰、礼物等 插件
第二十七章:时间复杂度与优化
Debug on pure method is called
光波导应用中的真实光栅效应
消息队列的技术选型
理解:野指针,空指针,失效指针。
HCIE学习记录——数据封装与常用协议(TCP/UDP)
MySQL协议长什么样子
排序方法汇总(C语言)
Unity-3D数学
类模板/赋值运算和加等运算
分布式一致性协议-Raft









