हिंदी

What is a Decrement Operator in Java? Explain with an example.

Advertisements

प्रश्न

What is a Decrement Operator in Java? Explain with an example.

स्पष्ट कीजिए
Advertisements

उत्तर

The Decrement Operator (--) in Java is a unary operator used to decrease the value of a variable by one. It can be used in two forms: Pre-decrement (--a), which decreases the value before it is used, and Post-decrement (a--), which decreases the value after it is used.

Example:

int a = 10;
a--;
System.out.println(a);

Output:

9

In the above example, the variable a is initialised with the value 10. The decrement operator (--) decreases its value by one. Therefore, after executing a--, the value of a becomes 9.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - EXERCISE [पृष्ठ १३१]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
EXERCISE | Q 17. (ii) | पृष्ठ १३१
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×