DEV Community

Cover image for C++ Ma'lumot turlari
islomAli99
islomAli99

Posted on

5

C++ Ma'lumot turlari

Assalamu aleykum bugun siz bilan Data types - Ma'lumot turlari xaqida ko'rib chiqamiz.

#include <iostream>
using namespace std;
​
int main() {
  int myNum = 5;               // Butun (whole number)
  float myFloatNum = 5.99;     // O'nli kasr
  double myDoubleNum = 9.98;   // O'nli kasr Float bilan chegarasi bilan farq qiladi.
  char myLetter = 'D';         // Char
  bool myBoolean = true;       // Boolean (Rost yoki Yolg'on)
  string myText = "Hello";     // Satr
}
Enter fullscreen mode Exit fullscreen mode

Ma'lumotlarning asosiy turlari

Ma'lumotlar turi o'zgaruvchini saqlaydigan ma'lumot hajmi va turini belgilaydi:

Image description

Raqam turlari - integer = int - butun sonlar uchun.

#include <iostream>
using namespace std;
​
int main() 
{

  int butun = 13; // Butun (whole number)

return 0;
}
Enter fullscreen mode Exit fullscreen mode

Raqam turlari - float - kasr sonlar uchun.

#include <iostream>
using namespace std;
​
int main() 
{

  int mn = 13.15; // Haqiqiy (whole number)

return 0;
}
Enter fullscreen mode Exit fullscreen mode

double - kasr sonlar uchun.

Misol uchun:

#include <iostream>
using namespace std;

int main()
{

double myNum = 19.99;
cout << myNum;

return 0;
}
Enter fullscreen mode Exit fullscreen mode

float va double

float - nuqtadan keyin uzida 8 ta sonlar xotirasida saqlay oladi xolos.
*double *- esa nuqtadan keyin uzida 16 ta sonlar xotirasida saqlay oladi xolos.

String - satr turlari;
String - turi belgi (matn yoki tekst) bir ketma-ketlikni saqlash uchun ishlatiladi. Satrda yozilganidek qo'shtirnoq yozishni unutmang.

Misol uchun:

#include <iostream>
using namespace std;

int main()
{

cout << "Biz C++ o'rganishni boshladik";

return 0;
}
Enter fullscreen mode Exit fullscreen mode

char - belgilar turlari.
char - ma'lumotlar turi saqlash uchun foydalanadigan yagona belgi. Belgilar 'A', yoki 'c' kabi bir tirnoq bilan o'ralgan bolishi kerak:

Misol uchun:

#include <iostream>
using namespace std;

int main()
{

char belgi = 'A';
char belgi1 = 'c';
char belgi2 = '#';

cout << belgi << endl;
cout << belgi1 << endl;
cout << belgi2;

return 0;
}
Enter fullscreen mode Exit fullscreen mode

Shu bilan bir qatorda, siz ma'lum bir belgilarni ko'rsatish uchun ASCII qiymatlaridan foydalanishingiz mumkin:

#include <iostream>
using namespace std;
​
int main()
 {
  char a = 65, b = 66, c = 67;
  cout << a;
  cout << b;
  cout << c;

return 0;
}
Enter fullscreen mode Exit fullscreen mode

Natija: ABS

Boolean turlari

Boolean ma'lumotlar turi bilan e'lon qilinadi bool kalit so'z va faqat qiymatlarni qabul qilishi mumkin true, yoki false. Qiymat qaytarilganda true = 1 va false = 0.

Misol uchun:

#include <iostream>
using namespace std;
​
int main() 
{
    bool togri = true;
    bool yolgon = false;
    cout << togri;  // Chiqadi 1 (true)
    cout << yolgon;  // Chiqadi 0 (false)

return 0;
}
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
zafar7709 profile image
zafar7709

Yordam berdi Rahmat

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay