DEV Community

Cover image for Increment/Decrement & Compound Assignment
Wahid Abduhakimov
Wahid Abduhakimov

Posted on

Increment/Decrement & Compound Assignment

Increment/Decrement
  • o'zgaruvchining qiymatini 1ga oshirish (++) yoki kamaytirish (--) uchun ishlatiladi
int x = 10;  // x = 10
int y = x++;    // y = 10, x = 11
int z = x++ + y++; // z = 21, x = 12, y = 11

cout << x << endl;
cout << y << endl;
cout << z << endl;
Enter fullscreen mode Exit fullscreen mode
  • postfix usulida increment/decrement o'zgaruvchidan keyin keladi va operator ustunligi juda past bo'ladi.

Masalan: x = y++; ifodasida increment operatori o'zgaruvchidan keyin kelgani sababli o'zlashtirish operatori birinchi bajariladi

    int x = 5;
    int y = x++;

    cout << x << endl; // 6
    cout << y << endl; // 5
Enter fullscreen mode Exit fullscreen mode
  • prefix usulida increment decrement o'zgaruvchidan oldin keladi va operator birinchi bajariladi

Masalan: x = ++y; ifodasida increment operatori o'zgaruvchidan avval kelgani sababli increment operatori birinchi bajariladi.

    int x = 5;
    int y = ++x;

    cout << x << endl; // 6
    cout << y << endl; // 6
Enter fullscreen mode Exit fullscreen mode

Assignment Compound
x = x + 1 x += 1
x = x - 1 x -= 1
x = x * 1 x *= 1
x = x / 1 x /= 1

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Retry later