Where "?" is used in C++ programms.

Where the question mark "?" is used in c++ programs other than ternary operators.
I think I haven't seen it in other places.

There is also the escape char: \? if it counts.
Nowhere (as an operator)
its is trianary operator ..
as per the below example

if( a > b ) ? return 1 : return 9;
> Where the question mark "?" is used in c++ programs other than ternary operators.

Trigraphs. For example:

1
2
3
4
5
??=include <iostream>

struct A ??< ??- A() ??< std::cout << "bye??/n" ; ??> ??> a ??( 5 ??) ;

int main() ??<??>


And inside comments, of course.
JLBorges,

Wow nice example, I just wanted to ask "Is that C++" ahahhaahh
Strictly speaking, neither C or C++ handle trigraphs as a language element. They are handled by the preprocessor.

Trigraphs exist so that C (and C++) can be used on computers which use a charset which doesn't include certain characters. For example, EBCDIC doesn't always provide curly {s and }s.
closed account (zb0S216C)
return cannot be used with the ternary operator.

Wazzak
Last edited on
return cannot be used with the ternary operator.
Not entirely accurate.
did you mean:
return a > b ? 1 : 9;
closed account (zb0S216C)
KBW, evidence? The ternary operator only accepts expressions. return is a statement which doesn't yield a value.

Wazzak
Last edited on
1
2
3
4
int main()
{
	true > false ? return 1 : return 9; //ERROR (expected an expression :)
}
return bInRange ? a : b;
closed account (zb0S216C)
Yes, that's valid, because the operator yields an expression which return accepts, not a statement.

Wazzak
Topic archived. No new replies allowed.