Decrement operator

nuriddin152

Nuriddin152

Posted on March 17, 2023

Decrement operator

Kamaytirish operatorining asosiy vazifasi o'zgaruvchining sonli sonini 1 qiymatiga kamaytirishdan iborat. Dasturlash tilida kamaytirish operatori “– –” belgisi bilan belgilanadi.

Image description

*rule *

Prefiks va Postfix Decrement operator pozitsiyalari bir xil funktsional qiymatlarga ega va agar ular hech qanday ifoda formatida ishlatilmasa, bir xil natijalarni beradi.

Example

#include <iostream>
using namespace std;


int main()

{

int x = 20 ; int y = 40;

--x;

y--;

cout << x << endl << y;

return 0;
}
Enter fullscreen mode Exit fullscreen mode

The result

19
39
Enter fullscreen mode Exit fullscreen mode

rule

`O'stirish operatorlari kabi, kamaytirish operatori ham har qanday iborada operator ishlatilsa, boshqacha ishlaydi.

Agar dekrement operatori Prefiks pozitsiyasida ishlatilayotgan bo'lsa, u holda Increment funktsiyasi ifodadan oldin bajariladi.

Agar pasaytirish operatori Postfix pozitsiyasida ishlatilayotgan bo'lsa, u holda Increment funktsiyasi ifodani baholashdan keyinamalga oshiriladi.`

#include <iostream>
using namespace std;

int main()
{
int x =  90;
int a;
cout <<"Value of x = "<< --x << endl;

a = x--;

cout <<"Value of a = "<< a << endl;

cout <<"New Value of x = "<< x << endl;

return 0;
Enter fullscreen mode Exit fullscreen mode

The result

89
89
88
Enter fullscreen mode Exit fullscreen mode

Tushuntirish

Birinchi "cout" bayonotimizda Pre-Decrement operatori ishlatiladi. Shunday qilib, "x" qiymati 1 ga kamayadi, ya'ni x = x - 1 = 90 - 1 = 89

Keyin ‘a = x — —’ ifodasidagi “a” o‘zgaruvchisiga qiymat beramiz.

Bu shuni anglatadiki, avval "x" qiymati "a" ga tayinlanadi, keyin esa "x" 1 ga kamayadi. Demak, a = 9 chiqish, x = 88 ning yangi qiymati.

💖 💪 🙅 🚩
nuriddin152
Nuriddin152

Posted on March 17, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024