मराठी

Differentiate between the following: Post increment and Pre increment operator

Advertisements

प्रश्न

Differentiate between the following:

Post increment and Pre increment operator

What is the difference between post-increment and pre-increment? If a = 4 give values of ++a and a++.

फरक स्पष्ट करा
Advertisements

उत्तर

Post Increment Operator

Pre Increment Operator

1. The post increment operator increases the value of a variable by 1 after its current value is used in an expression.

1. The pre increment operator increases the value of a variable by 1 before its new value is used in an expression.

2. In post increment, the original value of the variable is used first, and then its value is increased by 1.

2. In pre increment, the value of the variable is increased by 1 first, and then the updated value is used.

3. The post increment operator is represented by placing the increment operator (++) after the variable.

3. The pre increment operator is represented by placing the increment operator (++) before the variable.

4. The syntax of the post increment operator is variable++.

4. The syntax of the pre increment operator is ++variable.

5. When used in an assignment expression, the post increment operator assigns the original value of the variable before incrementing it.

5. When used in an assignment expression, the pre increment operator increments the variable first and then assigns its updated value.

6. Example: If a = 10, then b = a++; assigns 10 to b and increases a to 11.

6. Example: If a = 10, then b = ++a; increases a to 11 and assigns 11 to b.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×