25. Data Types (Type Conversion)

sunnat_qayumov

Sunnat Qayumov

Posted on October 14, 2024

25. Data Types (Type Conversion)

a) Implicit va Explicit turdagi konversiyalar o'rtasidagi farq nima?

  1. Implicit (Bevosita) o'zgarish: Kichik hajmdagi qiymatlarni katta hajmdagi qiymat turlariga osonlik bilan o'zgartirish mumkin.

    - Masalan: `int` -> `long` yoki `float` -> `double`
    
  2. Explicit (Aniq) o'zgarish: Bu o'zgarish katta hajmdagi qiymatni kichik hajmdagi qiymatga o'zgartirishda amalga oshiriladi. Ular uchun maxsus casting kerak bo'ladi.

    - Masalan: `double` -> `int`
    

b) Quyidagi kod qaysi turdagi konversiyalarni amalga oshiradi?

int x = 10;
double y = x;

*Javob: * int -> double Implicit

Bu yerda int ni double da o'zgartirsa bo'ladi ammo doubleni int tipiga o'zgartirib bo'lmaydi.

💖 💪 🙅 🚩
sunnat_qayumov
Sunnat Qayumov

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