answersLogoWhite

0

What is unary minus operator?

Updated: 8/10/2023
User Avatar

Wiki User

11y ago

Best Answer

No. The subtraction operator is a binary operator that returns the result of subtracting the rhs operand from the lhs operand. The unary minus operator simply negates the rhs operand.

int x = -5; // unary minus. x is (-5)

int y = -x; // unary minus. y is (+5)

y -= x; // binary minus/assign operator. y is (+10)

--x; // unary decrement operator. x is (-6)

y -= (-x); // binary minus/assign and unary minus operators. y is(+4)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The unary minus operator negates the operand.

int a = 3;

a = -a; // a 3

a = -5; // unary minus operator used with literal constant.

a = 5 * (-3); // same usage

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is unary minus operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is plus operator is it unary or binary?

There is no unary plus in C, but if there were, it would have only one operand, unlike the binary plus which has two: x = a + b; /* binary plus */ x = + b; /* unary plus -- not in C*/ x = a - b; /* unary plus */ x = - b; /* unary minus */


What operator is a unary operator as it works with only one operand?

Yes, a unary operator is an operator that only has one operand. Examples of unary operators are negative (-), positive (+), increment (++), decrement (--), address of (&), dereference (*), logical not (!), sizeof, one's complement (~), new, and delete.


Which is the unary operator used to dereference a pointer and return the value stored in it?

The asterisk (*) operator dereferences a pointer and returns the value stored in the memory pointed to by the pointer.


Explain the Difference between bitwise operator ' and ' and address operator ' and ' of pointer?

The bitwise logical operator and (&) calculates the bitwise logical and of two integral values. It is a binary operator.The address of (&) operator returns the address of the value to its right. It is a unary operator.The distinction between the two is one of context. The logical and operator will follow (and be preceeded by) a value, while the address of operator will follow an operator.


What is difference between conditional operator and bitwise operator?

A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.A binary operator is simply an operator that has two parts, written to the left and to the right of the operator, e.g.:1 + 2The binary operator can be a logical operator ("and", "or", "xor", etc. - but "not" is a unary operator), or it can be in some other category, like the arithmetic operator shown above.

Related questions

How unary minus can be overload in c plus plus?

type operator- ();


What is plus operator is it unary or binary?

There is no unary plus in C, but if there were, it would have only one operand, unlike the binary plus which has two: x = a + b; /* binary plus */ x = + b; /* unary plus -- not in C*/ x = a - b; /* unary plus */ x = - b; /* unary minus */


What is unary mening?

'not' for instance is a unary operator. It is unary in the sense that it operates on a single item. In contrast a binary operator such as addition operates on two items.


Does a unary expression consists of only one operand with no operator?

No, a unary expression consists of one operand and one operator


What operator is a unary operator as it works with only one operand?

Yes, a unary operator is an operator that only has one operand. Examples of unary operators are negative (-), positive (+), increment (++), decrement (--), address of (&), dereference (*), logical not (!), sizeof, one's complement (~), new, and delete.


What is mening?

'not' for instance is a unary operator. It is unary in the sense that it operates on a single item. In contrast a binary operator such as addition operates on two items.


What is the difference between unary and binary?

In programming a unary and binary operator defines how many components make up an expression.


Give me the answer Difference between unary and binary operator?

A unary operator is one which operates on just one number, e.g. x2 or -x. A binary operator is one which takes two numbers, e.g. x + y or xy. Note that this has nothing to do with binary vs. decimal arithmetic. This term is commonly used to distinguish between the two buttons which have a '-' sign on a calculator. The unary '-' operator button is used to change the sign of a number entered, and the binary '-' operator button is used to subtract two numbers, which is quite a different thing. The unary '-' button is commonly labelled '+/-'.


What is difference between binary and unary operator in c language?

The number of arguments will be one for the unary operators and two for the binary operators. In the case of unary operators, the argument must be of the same type as that of the enclosing class or structure.


Why do my two different calculators both show minus three squared as negative nine instead of positive?

The minus (unary) operator is of lower precedence than the exponent. To force the square of a negative on some calculators you may need to surround the number in parentheses. E.g.


How many arguments are required in the definition of an overloaded unary operator?

any number of arguments


Which is dummy operator in c?

In C, the sizeof operator can be considered a dummy operator because it does not perform any operations on the data but simply returns the size in bytes of a variable or a data type.