解释指针的指针问题 [英] explain the pointers to pointers issue

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

问题描述

我是新成C,我试图让指针一握。我碰到这个前pression

I'm new into C and I'm trying to get a grip on pointers. I came across this expression

char *foo = *(char **)bar;

到底是怎么回事呢?据我所知,是* **的指针是指针的指针,但我真的不明白是什么 *(字符**)栏

编辑:
值得一提的是酒吧声明为const void *的栏

edit: worth to mention that bar is declared as const void *bar

推荐答案

初学者和专家都可以受益于获取基础非常坚实的。

Beginners and experts alike can benefit from getting the basics really solid.


  • A的变量的类型t 的是一种可以用来存储或取得一个的值的存储位置的类型t。

  • A的指针的以T是的

  • 运用对其操作 * 来一个指针T产生的类型t变量。

  • A "variable of type t" is a storage location which can be used to store or fetch a value of type t.
  • A "pointer to t" is a value.
  • Applying the dereferencing operator * to a "pointer to t" produces a "variable of type t".

那么,我们得到了?

void *bar = whatever;
char *foo = *(char **)bar;


  • 的类型是指向无效的变量。

  • 的类型是字符指针的变量。

  • 铸造的char ** 读变量并获取型指针无效的值。然后,该值被转换成类型的值指向字符指针。

  • 取消引用该值产生的类型字符指针的变量。

  • 该变量的值就是取出,并将其值赋给变量

    • bar is a variable of type "pointer to void".
    • foo is a variable of type "pointer to char".
    • casting bar to char** reads the variable bar and fetches a value of type "pointer to void". That value is then converted into a value of type "pointer to pointer to char".
    • Dereferencing that value produces a variable of type "pointer to char".
    • The value of that variable is then fetched, and the value is assigned to variable foo.
    • 请有意义吗?

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

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