4

I saw this code

a<?=b; // (a and b are int)

from the solution of Google Code Jam.

but my VS shows an error on '?'

I only know the following:

a>b?a=0:b=0;

Thanks.

czhao86
  • 79
  • 5

3 Answers3

9

Old operator; it's a (since removed) gcc extension for 'minimum'. That is:

a <?= b;

is the same as:

a = a < b ? a : b;
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

A nonstandard GCC extension to C++ allows <? as an operator which is equivalent to min. I haven't seen <?= before, but presumably it's an in-place version; that is, a <?= b is equivalent to a = min(a,b).

Note that the GCC developers woke up the next morning and realized what a bad idea that was. The operator is now deprecated.

Sneftel
  • 40,271
  • 12
  • 71
  • 104
1

If a happens to be larger than b, it would set a to b.

Essentially the same as:

a = a < b ? a : b;

Example:

int a = 5;
int b = 2;
a<?=b; //a is now 2!

I wouldn't advocate actually using such a solution though, it is horrible.

As others have said, it's part of a nonstandard GCC extension, but please don't use it.

Profan
  • 181
  • 1
  • 9