什么是指针? [英] What is a Pointer?

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

问题描述

在许多C风格的语言以及某些较旧的语言(例如Fortran)中,可以使用 Pointers (指针).

In many C flavoured languages, and some older languages like Fortran, one can use Pointers.

作为只真正使用基本的Javascript和ActionScript进行编程的人,您能否向我解释一下Pointer是什么,以及它最有用的是什么?

As someone who has only really programmed in basic, javascript, and actionscript, can you explain to me what a Pointer is, and what it is most useful for?

谢谢!

推荐答案

指针并不像听起来那样难.正如其他人已经说过的那样,它们是保存其他变量地址的变量.假设我想给您指示去我家的路.我不会给你我家的照片或我家的比例模型;我只想给你地址.您可以从中推断出所需内容.

Pointers are not as hard as they sound. As others have said already, they are variables that hold the address of some other variable. Suppose I wanted to give you directions to my house. I wouldn't give you a picture of my house, or a scale model of my house; I'd just give you the address. You could infer whatever you needed from that.

以相同的方式,许多语言在按值传递和按引用传递之间进行区分.从本质上讲,这意味着我每次引用该对象时都会传递整个对象吗?或者,我只说出它的地址,以便其他人可以推断出他们的需求吗?

In the same way, a lot of languages make the distinction between passing by value and passing by reference. Essentially it means will i pass an entire object around every time I need to refer to it? Or, will I just give out it's address so that others can infer what they need?

大多数现代语言通过找出指针何时有用并为您进行优化来隐藏这种复杂性.但是,如果您知道自己在做什么,则在某些情况下手动指针管理仍然有用.

Most modern languages hide this complexity by figuring out when pointers are useful and optimizing that for you. However, if you know what you're doing, manual pointer management can still be useful in some situations.

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

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