DEV Community

Sherzod5048
Sherzod5048

Posted on

C++ da operatorlar

Assalomu alaykum!
Operatorlar - mavzusida davom etamiz.

  • Increment/Decrement operatorlar

"++" va "--" operatorlari o'zgaruvchidagi qiymatni bittaga oshiradi yoki kamaytitadi:

#include <iostream>
#include <iomanip>

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

  cout << n;
  return 0;
}
Enter fullscreen mode Exit fullscreen mode

Bu yerda n oz'garuvchisidagi qiymat bittaga oshirildi.

#include <iostream>
#include <iomanip>

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

  cout << n;
  return 0;
}
Enter fullscreen mode Exit fullscreen mode

Bu yerda esa n oz'garuvchisidagi qiymat bittaga kamaytirildi.

Agar kodda o'zgaruvchini oldidan increment/decrement oldin kelsa birinchi bo'lib incremant/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 increment/decrement o'zgarucvhidan keyin kelsa avval boshqa buyruqlar bajarilib keyin increment/decrement amallari 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
5
6
Enter fullscreen mode Exit fullscreen mode

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more