Conditional operator

munisa_kuranbekova_078e1e

Munisa Kuranbekova

Posted on November 2, 2024

Conditional operator

Conditional operator - ingliz tilidan tarjima qilinganda shart operatori degan ma'noni anglatadi.
Uning qisqacha syntaxi quyidagicha:
Condition ? A : B;
Kodga o'tadigan bo'lsak:

#include <iostream>

using namespace std;

int main()
{  

    int son;
    cin >> son;

int result = son > 0? 1 : 0;

cout << result << endl;


    return 0;
}

Enter fullscreen mode Exit fullscreen mode

kodni tahlil qiladigan bo'lsak son 0 dan kattami yoki yo'qmi shuni tekshiradi va resultga saqlaydi. Son o'zgaruvchisiga kiritgan sonimiz 0 dan katta bo'lsa 1 ni yo'qsa nolni chop etadi.

💖 💪 🙅 🚩
munisa_kuranbekova_078e1e
Munisa Kuranbekova

Posted on November 2, 2024

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

Sign up to receive the latest update from our blog.

Related