无法理解表示法:带指针的*和** [英] Not able to understand the notations : * and ** with pointers

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

问题描述

我的指针有问题.我知道这是怎么做的:

I have a problem with the pointers. I know what this does:

*name

我知道这是一个指针.

I understand that this is a pointer.

我一直在搜索,但是我既不了解它的功能,也没有找到有用的信息

I've been searching but I do neither understand what this one does nor I've found helpful information

**name

上下文是int ** name,不是乘法

The context is int **name, not multiplication

有人可以帮我吗?

推荐答案

注意:没有适当的上下文,*name**name的用法不明确.它可能是肖像(a).解引用运算符(b)乘法运算符

NOTE: Without the proper context, the usage of *name and **name is ambiguous. it may portrait (a). dereference operator (b) multiplication operator

考虑到您正在谈论这样的情况

Considering you're talking about a scenario like

  • char * name;
  • char **name;
  • char * name;
  • char **name;

在代码中,

  • *name

name是指向char的指针.

  • **name

name是一个指向char的指针.

name is a pointer, to the pointer to a char.

请不要与双指针"混淆,双指针"有时用于表示指针的指针,但实际上应该表示指向双精度数据类型变量的指针.

下面的视觉

如上所述,我们可以说

char value = `c`;
char *p2 = &value;   // &value is 8000, so p2 == 8000, &p2 == 5000
char **p1 = &p2;     // &p2 == 5000, p1 == 5000

因此,这里的p1是指针到指针的指针.希望现在能使事情变得清楚.

So, p1 here, is a pointer-to-pointer. Hope this make things clear now.

这篇关于无法理解表示法:带指针的*和**的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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