0

Recently, I came across some weird syntax in C code similar to this:

int b = ({
   printf("some code");
   2;
});

As expected, the code runs and b is set to 2. However, removing the parentheses around the curly braces results in an error:

int b = {
   printf("some code");
   2;
};

What is this called and how does it work? Why do I need the parentheses?

Employed Russian
  • 182,696
  • 29
  • 267
  • 329
Rotartsi
  • 497
  • 5
  • 14

0 Answers0