| 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?
| |||
|
|
|||
| 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".
<? 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;
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;
but you can't
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. | |
|
|
|