3
#include<stdio.h>
int main()
{
  printf("%d\n", 4 ?: 8);
}

According to the C standard this program is invalid because it is missing an expression between the ? and :.But The interesting thing is that there is when I compile the code it is printing 4.how come it will print 4 rather than showing any compile error

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
user2416871
  • 543
  • 1
  • 4
  • 13

1 Answers1

6

This is a gcc extension.

x ? : y

is equivalent to

x ? x : y

See here for detail.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294