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!
== (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.
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
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.
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?
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.
#include <iostream>
usingnamespace 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 })
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.