解释指针的指针问题

编程入门 行业动态 更新时间:2024-10-22 21:22:48
本文介绍了解释指针的指针问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新成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.
    • 请有意义吗?

更多推荐

解释指针的指针问题

本文发布于:2023-11-30 20:36:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!