13.Operators (Advenced)

zahro_11eecc01a1cfe5142b9

Zahro

Posted on October 14, 2024

13.Operators (Advenced)

a) += operatori qanday ishlaydi? Misol keltiring.

+= operatori o'zgaruvchiga mavjud qiymatga qo'shilgan yangi qiymatni berish uchun ishlatiladi. Misol:

int number = 5;
number += 10;
Console.WriteLine(number);
Enter fullscreen mode Exit fullscreen mode

Natija: 15

Bu kodda number += 10 amali number o'zgaruvchisining qiymatini 10 ga oshiradi va 15 ni qaytaradi.

a) Post-increment va pre-increment operatorlari qanday ishlaydi?

Post-increment (x++): O'zgaruvchining hozirgi qiymatini ishlatadi, keyin uni oshiradi.

Misol:

int x = 5;
int y = x++;  // y = 5, x = 6
Enter fullscreen mode Exit fullscreen mode

Bu yerda x++ operatori x ning avvalgi qiymatini qaytaradi (5), keyin x qiymati oshiriladi (6).

Pre-increment (++x): O'zgaruvchining qiymatini avval oshiradi, keyin uni ishlatadi.

Misol:

int x = 5;
int y = ++x;  // y = 6, x = 6

Enter fullscreen mode Exit fullscreen mode

Bu yerda ++x avval x ni 6 ga oshiradi, keyin y ga qiymatni beradi (6).

πŸ’– πŸ’ͺ πŸ™… 🚩
zahro_11eecc01a1cfe5142b9
Zahro

Posted on October 14, 2024

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

Sign up to receive the latest update from our blog.

Related