当前位置:网站首页>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)的数组的地址
边栏推荐
猜你喜欢
随机推荐
Unity-Ads广告插件
【进程间通信】:管道通信/有名/无名
深入理解负载均衡
C语言函数调用过程-汇编分析
shader 和 ray marching
【网络安全】学习笔记 --00
Test case exercises
Project: combing the database table
OpenPose 运行指令 ([email protected])
面试汇总
富文本编辑
关于混淆的问题
implement tcp copa on ns3
unity-shader(中级)
CDH (computational Diffie-Hellman) problem and its differences with discrete logarithm and DDH problems
2342. 数位和相等数对的最大和 哈希优化
【进程间通信】信号量的使用/共享内存
change the available bandwidth of tcp flow dynamically in mininet
许多代码……
戴森球计划这个游戏牛逼