What's this C++ syntax that puts a brace-surrounded block where an expression is expected?

后端 未结 4 1477
借酒劲吻你
借酒劲吻你 2020-11-30 02:50

I came across this weird C++ program.

#include 
using namespace std;
int main()
{
  int a = ({int x; cin >> x; x;});
  cout << a;         


        
4条回答
  •  臣服心动
    2020-11-30 03:30

    It's a GCC extension. Compile your code with the -pedantic flag if you want to get rid of stuff like this (and you really do want to).

提交回复
热议问题