Two problems

closed account (28poGNh0)
First :

What is an unary operator,and a binary operator ,can you site them all to me

Second :

What is the difference between unary minus and minus
coz in the precedence of operators unary minus and minus are differente
Last edited on
closed account (o3hC5Di1)
Hi there,

A unary operator is an operator which takes only a single argument. Some examples include &, *, !, or postfix or prefix increment/decrement. A binary operator, on the other hand, takes two arguments, examples include binary plus/minus, ( a+b, two arguments), insertion and extraction operators (cout << a, two arguments), etc.

The difference between binary minus and unary minus is that binary subtracts the right operand from the left operand and returns the result, i.e. 4 - 3, 3 is subtracted from 4 and 1 is returned. Unary minus changes the sign (and possibly the type) of a number:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void test(unsigned short i)
{
    std::cout << "test called with an unsigned int";
}

void test(int i)
{
    std::cout << "test called with a signed int";
}

int main()
{
    unsigned short i=56;
    test(-i);
    return 0;
}
test called with a signed int.


Running example: http://coliru.stacked-crooked.com/a/df1ea66fc33e5664
Hope that helps, please do let us know if you have any further questions.

All the best,
NwN
Seems to me you are a troll.
closed account (28poGNh0)
Thanks a lot @NwN for the great/fact reply

one last question though ,how did you do the "purple field ,grey field" ? thanks again :)
closed account (o3hC5Di1)
Hi there,

Most welcome.

Here is a link describing the use of tags on this forum: http://www.cplusplus.com/articles/z13hAqkS/
Look under "2.1 output tags, combining the above".

@a k n - He's not trolling, he's posting unrelated questions in different topics, as he is supposed to.

All the best,
NwN
Last edited on
closed account (28poGNh0)
Thanks @NwN again and again
and speeking of trolling! I still got mores threads to post here and they are discussing
different topics
.
Topic archived. No new replies allowed.