DEV Community

Sherzod5048
Sherzod5048

Posted on

C++ da operatorlar

  • Increment/Decrement operatorlar "++" va "--" operatorlari o'zgaruvchidagi qiymatni bittaga oshiradi yoki kamaytiradi.
#include <iostream>
#include <iomanip>

using namespace std;
int main() {
  int n = 5;
  ++n;

  cout << n;

  return 0;
}
Enter fullscreen mode Exit fullscreen mode
6
Enter fullscreen mode Exit fullscreen mode

qiymatni bittaga oshiradi yoki kamaytiradi.

#include <iostream>
#include <iomanip>

using namespace std;
int main() {
  int n = 5;
  --n;

  cout << n;

  return 0;
}
Enter fullscreen mode Exit fullscreen mode
4
Enter fullscreen mode Exit fullscreen mode

Agar kadimizda Increment/decrement o'zgaruvchidan oldin kelsa birinchi bo'lib Increment/decrement hisoblanib keyin boshqa buyruqlar bajariladi:

#include <iostream>
#include <iomanip>

using namespace std;
int main() {
  int n = 5;

  cout << ++n << endl;
  cout << n;

  return 0;
}
Enter fullscreen mode Exit fullscreen mode
6
6
Enter fullscreen mode Exit fullscreen mode

Lekin kadimizda Increment/decrement o'zgaruvchidan keyin kelsa birinchi bo'lib boshqa buyruqlar bajarilib keyin Increment/decrement hisoblaniladi:

#include <iostream>
#include <iomanip>

using namespace std;
int main() {
  int n = 5;

  cout << n++ << endl;
  cout << n;

  return 0;
}
Enter fullscreen mode Exit fullscreen mode
5
6
Enter fullscreen mode Exit fullscreen mode

Top comments (0)