迭代 char** 为什么这有效?

发布于 2024-12-25 04:09:57 字数 512 浏览 2 评论 0原文

我拿起这段代码,将其复制到我的程序中。这对我来说似乎是一种迭代 char** 的新方法:

char** vArray;          // The array containing values

// Go throught properties
if(szKey == "KeyMgmt")
{
    vArray = (char**)g_value_get_boxed((GValue*)value);
    for( ; vArray && *vArray ; vArray++)  // Why does this work ?!
        pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
    // ...
}

它看起来像一个魅力,但我不明白为什么! vArray 应该包含一个地址,对吧? *vArray 是“字符串”值。那么,为什么当我将一个地址与其值“与”时,这会给我一个相等性呢?

I picked up a this piece of code I copy past to my program. This seems to be a new way to me to iterate through char**:

char** vArray;          // The array containing values

// Go throught properties
if(szKey == "KeyMgmt")
{
    vArray = (char**)g_value_get_boxed((GValue*)value);
    for( ; vArray && *vArray ; vArray++)  // Why does this work ?!
        pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
    // ...
}

It looks like to work like a charm but I don't understant why! vArray is Supposed to contain an adress right? And *vArray the "string" value. So why when I "AND" an address with its value this give me an equality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我三岁 2025-01-01 04:09:57

vArray && *vArray 相当于 (vArray != NULL) && (*vArray != NULL)

首先检查指针 vArray 是否不是 NULL,并且假设它不是 NULL ,检查它指向的指针是否不是NULL

vArray && *vArray is equivalent to (vArray != NULL) && (*vArray != NULL)

It's first checking that the pointer vArray isn't NULL and, assuming it is not NULL, checking that the pointer it points to isn't NULL.

╰沐子 2025-01-01 04:09:57

循环条件是

vArray && *vArray

这基本上是简写

(vArray != 0) && (*vArray != 0)

,如果 char** 指针非空并且指向非空的 char* ,则循环条件为 true。

The loop condition is

vArray && *vArray

This is basically shorthand for

(vArray != 0) && (*vArray != 0)

which is true if the char** pointer is non-null and points to a char* which is non-null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文