焦炭**应付字符串? [英] char** to cope with string?

查看:111
本文介绍了焦炭**应付字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,当我遇到的char **来了,是不是真的有必要,以应对串?结果
例如:

I got quite confused when I came across char**, is it really necessary to cope with string?
For example:

double strtod(const char *nptr,char **endptr);

如果 endptr 不为空,一个指针停止扫描的字符存储在该位置指向 endptr 。 --- MSDN结果
这是相当复杂的,为什么不直接指针复制到字符 endptr ?通话后,所有的计算可以通过指针的值传递给 endptr ,因为我认为可以实现。结果
的char ** 真的需要?

If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr. ---MSDN
This is quite complicated, why not just copy pointer to the character to endptr? All computations after the call can be achieved by passing the pointer's value to endptr as I think.
Is char** really needed?

推荐答案

想象一下,有一个名为 my_type ,和你有一个调用的函数 foo的类型()需要一个指向一个 my_type ,以便它可以修改它:

Imagine there's a type called my_type, and you have a function called foo() that needs a pointer to a my_type so that it can modify it:

void foo(my_type *t);

现在,让我们看看如何 my_type 实际上是定义的:

Now, lets look at how my_type is actually defined:

typedef char* my_type;

因此​​,如果类型是已经是指针也没关系。如果你想要一个指针传递给该类型的变量,你需要它的地址。因此,分解:

So it doesn't matter if the type is already a pointer. If you want to pass a pointer to a variable of that type, you need its address. So the decomposition of:

my_type *t

是:

char **t

当你想要一个指针类型的变量的char * ,你需要一个的char **

这篇关于焦炭**应付字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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