为什么我们有除void以外的指针 [英] Why do we have pointers other than void

查看:99
本文介绍了为什么我们有除void以外的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们有不同的指针,例如intfloatchar. void指针是唯一可以容纳所有其他指针的指针.

I know that we have different pointers like int, float, and char. A void pointer is the only pointer which can hold all others.

是否存在其他指针仅仅是为了灵活地执行指针算术?

Do the other pointers exist only for the flexibility to do pointer arithmetic?

还有其他原因导致C语言中存在除void之外的其他指针吗?

Is there any other reason that pointers other than void are present in C language?

推荐答案

类型安全.定义指针的类型有助于编译器在尝试通过指针使用错误类型的数据时发现错误.这就是C首先具有类型的原因.

Type safety. Defining the type of pointers helps the compiler find errors where you are trying to use data of the wrong type through a pointer. That's the reason C has types in the first place.

这篇关于为什么我们有除void以外的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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