C语言中数组的结尾 [英] End of array in C language

查看:341
本文介绍了C语言中数组的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道对于字符数组,我们使用'\ 0'标识其结尾,其他类型的数组呢?

We know that for character arrays we have the '\0' to identify its end, what about other types of arrays?

我认为它不是特殊字符,例如'\ 0',因为要声明一个由n个元素组成的整数数组,例如,您只分配n * sizeof(int),但是对于字符数组,我们将其记为'\ 0 '.

I presume it's not a special character such as the '\0' since to declare an integer array of n elements for example you just allocate n * sizeof(int), yet for a character array we account for the '\0'.

推荐答案

C数组没有结束标记.

C arrays don't have an end marker.

作为程序员,您有责任跟踪数组的分配大小,以确保您不要尝试访问超出分配大小的元素.

It is your responsibility as the programmer to keep track of the allocated size of the array to make sure you don't try to access element outside the allocated size.

如果您访问的元素超出了分配的大小,则结果为未定义的行为.

If you do access an element outside the allocated size, the result is undefined behaviour.

这篇关于C语言中数组的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆