What does the unary minus operator do?

Prepare for the C Certified Entry-Level Programmer Test using flashcards and multiple choice questions with detailed hints and explanations. Sharpen your programming skills and succeed in your certification exam!

The unary minus operator is designed to negate the value of a single operand. In programming, when you apply this operator to a variable or a constant, it inverts its sign. For example, if you have a variable containing a positive number and you apply the unary minus operator to it, the result will be a negative number of the same magnitude. Conversely, if the operand is a negative number, the unary minus would convert it to a positive number. This operator effectively provides a simple mechanism to change the sign of numerical values within expressions, which is essential for arithmetic operations that involve subtraction or determining negative values.

The other options describe different operations that are not related to the unary minus operator. For instance, the addition of two numbers involves a binary operator, while converting an integer to a float is a type conversion, and the modulus operation calculates the remainder of a division, neither of which pertains to the unary minus functionality.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy