我可以转换成结构吗?

时间:2021-01-08 17:38:12

标签: c casting

编辑 - 在评论中回答问题。

我一直在浏览 cppreference.com 并找到了一段代码,并在对其进行了一些详细阐述后得到了以下结果:

#include <stdio.h>

struct T { double a[4] };

struct T f(void) { return (struct T){3.15}; }    //Is that casting into struct T?? 
                                                 //But isn't casting into non-scalar not possible?

int main (void)
{
    double d = *f().a;                           //What?
    printf("%f\n", d);
}

与主题相关的问题在第一条评论的行上。我有点明白发生了什么(我猜)但语法对我来说不清楚 - 有人可以详细说明吗?

附加问题(如果可能的话)是关于第二条注释的那一行——所以,我可以像在表达式中一样使用函数的返回值,就像在给定的例子中一样?

0 个答案:

没有答案