C 类型和表达式

问题描述 投票:0回答:1

我在测验中遇到了这个问题,但我不确定答案:

给定

int *foo(void)
,下列表达式的类型是什么?其中哪些是左值?

*foo()  
 &foo()  
 foo()  
 foo  
 &foo

我是这么想的:

 *foo()  type: return int so int?, non-lvalue
 &foo()  type: address of foo(), not sure the type, lvalue (?) because the address has location in memory
 foo()  not sure about this one
 foo    not sure
 &foo   have no clue.

我很乐意理解背后的逻辑,因此如果我看到类似的表达式,我可以理解它的类型和左值。

非常感谢。

c types expression
1个回答
0
投票
  • *foo()
    int
  • &foo()
    :语法错误
  • foo()
    -
    int *
  • foo
    - 函数类型在表达式中衰减为函数指针
    int *(*)(void)
  • &foo
    - 函数指针
    int *(*)(void)
© www.soinside.com 2019 - 2024. All rights reserved.