Weird initialization in C

前端 未结 1 1700
花落未央
花落未央 2021-01-17 19:38

I have this piece of code and i don\'t know how it works

#include 

int main(void)
{
    int numero = ({const int i = 10; i+10;});

    printf         


        
相关标签:
1条回答
  • 2021-01-17 20:19

    It's a GCC statement expression. It executes the statements in it, and returns the value evaluated in the last statement. Thus numero is initialized to 20. If you delete the second part, there is no expression as the last statement, so it can't get a value from the statement expression.

    The braces are necessary to disambiguate it from ordinary C parenthesized expressions.

    0 讨论(0)
提交回复
热议问题