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

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay