>?=

la8dm (2)
Is ">?=" an operator of C++? Or G++? What is the difference between G++ and C++?
How to search">?=" (i mean some special signs) in Google? Thanks a lot!

Happy Weekend!
Alex
programmingnewb (14)
>?= is no operator of C++.

these are operators of C++ :

== (equals to)
!= (does not equals to)
<= (less than or equals to)
>= (greater than or equals to)
< (less than)
> (greater than)
&& (AND)
|| (OR)

I'm sure there are few more, but these are the ones I know.
As for your question about the difference between C++ and G++,

I believe G++ is the C++ compiler of GNU. Anyway before you start programming, read the introduction on tutorials site, they explain what C++
is, and what you can do with it.

Anyway, Hope it helped ya
la8dm (2)
Hey,dude!
">?=" is an operator of C++, at least of "DEV C++ 4.9.9.2"
I did an experiment and figured it out that it equals:
"a>?=b " == " if(a>b) 'do nothing' else a=b;"
You can try it and post your feedback.
best,
Alex Lu
AzraelUK (57)
I've just updated my code on this question:
http://cplusplus.com/forum/beginner/71/

to use this crazy notation.

(a >?= b;) == (a = max(a, b);)
(a <?= b;) == (a = min(a, b);)

I'm using Code::Blocks, it works fine here too.
Last edited on
dirk (35)
A brand new operator? Wicked!
It's overloadable too (of course).
I wonder if there are more?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

class Cls {
    int n;
  public:
    Cls(int n_) { n = n_; }
    Cls& operator>?(Cls &b) { return ((n > b.n) ? *this : b); }
    friend ostream& operator<<(ostream &os, Cls &a);
};

ostream& operator<<(ostream &os, Cls &a) {
    return (os << '{' << a.n << '}');
}

int main() {
    int a = 3, b = 5;

    cout << (a >? b)           <<' '<<
            ((a > b) ? a : b)  <<' '<<
            max(a, b)          << endl;

    Cls ca(a), cb(b);
    cout << (ca >? cb) << endl;
}
Aepos (3)
Yeah, I know ">?=" is an operator, but, as previously stated, I've only seen it in 4.9.9.2, as this is the only Compiler and IDE that I use.

As for you, programmingnewb, those are the common mathematical operators, but, if you read the help topics, there are more operators such as "+=" (used in appending strings) and ">?=", as used as a mathematical operator and variable manipulator. As for the precise function, I'm unaware. la8dm seems correct, however.

- Aepos
maingeek (24)
It's one of a few shorthand notations. This particular one is shorthand for if-then-else...
dirk (35)
Just to keep things honest here, it is definitely not shorthand for "if then else".
1
2
3
a >? b           // expression evaluating to the greater of a or b
a >?= b         // combined with assignment which just means ...
a = a >? b      // ... assign greater of a or b to a 

<? is similar but for less than.

To Aepos, do you know any more of these "new" operators?
Last edited on
maingeek (24)
Actually, dirk the '?' is an alternative for the if-else statement.

"You can use the ? operator to replace if-else statements of the general form:
if (condition) expression;
else expression;
However, the target of both if and else must be a single expression-not another statement. The ? is called the ternary operator because it requires three operands. It takes the general form:
Exp1 ? Exp2 : Exp3
...The value is determined as follows: Exp1 is evaluated, if it is TRUE then Exp2 is evaluated, if it is FALSE, Exp3 is evalutated." (The Complete Reference C++ Fourth Edition, Herbert Schildt, pg63)

So unless I am reading this incorrectly, it would be a shorthand notation for my if-then-else statement.

~maingeek.

EDIT-I am not meaning to start a flame war, I am merely trying to expand my own understanding of the C++ language in addition to that of other people.
Last edited on
muzhogg (51)
A piece of sample code;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b;
    cout << "Enter any two integers: ";
    cin >> a >> b;
    
    int c = a > b ? a : b;  // If a > b THEN c = a ELSE c = b
    
    cout << "\nUsing [ c = a > b ? a : b ]";
    cout << "\n\n     The larger of the two numbers is " << c << "\n\n";
    
    // same as;
    cout << "\nUsing [ if (a > b) ... else ... ]";    
    if (a > b) cout << "\n\n     The larger of the two numbers is " << a;
    else cout << "\n\n     The larger of the two numbers is " << b;
    cout << "\n\n\n";
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Note that a BIG difference between using [exp1 ? exp 2 : exp3] and [if...else...] is that the first is NOT just a conditional statement, but actually returns a value, so you CAN;

 
variable = exp1 ? exp 2 : exp2


but you can't

1
2
variable = if (exp1) { ... }
           else { ... }


Although, of course, you could put variable assignments in your if...else... structure (if (exp1) { variable = a } else { variable = b })
Last edited on
maingeek (24)
Muzhogg,

Ok, I think I am beginning to understand how this is working. The only other time I have seen this in an actual program was in class, when we were using it with a return statement, which is exactly as you described. Thank you very much.
Topic archived. No new replies allowed.