当前位置:网站首页>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-编辑器扩展(Editor)
Unity-3D数学
TCP的三次握手和四次挥手
flex布局
queue的c实现
unity-shader(入门)
消息队列的技术选型
光波导应用中的真实光栅效应
C语言函数调用过程-汇编分析
关于推荐系统的随想
关于分布式的一些知识点
【网络安全】学习笔记 --00
HCIE学习记录——数据封装与常用协议(TCP/UDP)
Oauth2.0 认证服务器搭建
couldn't find 'libflutter.so' --flutter
极简式 Unity 获取 bilibili 直播弹幕、SC、上舰、礼物等 插件
【进程间通信】信号量的使用/共享内存
Exotic curiosity-a solution looking - bit operations
光栅区域衍射级数和效率的规范
剑指offer:反转链表