Additional Integer Types - Butun tipli o’zgaruvchilar
- Butun sonlar ta’riflanganda ko’rilgan tiplar oldiga unsigned (ishorasiz) ta’rifi qo’shilishi mumkin. Bu ta’rif qo’shilgan butun sonlar ustida amallar mod 2n arifmetikasiga asoslangandir . Bu erda n soni int tipi hotirada egallovchi razryadlar sonidir. Agar ishorasiz k soni uzunligi int soni razryadlar sonidan uzun bulsa, bu son qiyjmati k mod 2n ga teng bo'ladi. Ishorasiz k son uchun ga –k amali 2n – k formula asosida hisoblanadi. Ishorali ya’ni signed tipidagi sonlarning eng katta razryadi son ishorasini ko’rsatish uchun ishlatilsa unsigned (ishorasiz) tipdagi sonlarda bu razryad sonni tasvirlash uchun ishlatiladi.
- C++ supports several other integer types. The type short int, which may be written as just short,
- represents integers that may occupy fewer bytes of memory than the int type. If the short type occupies
- less memory, it necessarily must represent a smaller range of integer values than the int type. The C ++
- standard does not require the short type to be smaller than the int type; in fact, they may represent the
- same set of integer values. The long int type, which may be written as just long, may occupy more
- storage than the int type and thus be able to represent a larger range of values. Again, the standard does
- not require the long type to be bigger then the int type. Finally, the long long int type, or just
- long long, may be larger than a long. The C ++ standard guarantees the following relative ranges of
- values hold:
- short int<= int<= long int <= long long int
- unsigned short< unsigned < unsigned long < unsigned long long
Many computational tasks require numbers that have fractional parts. For example, the formula from mathematics to compute the area of a circle given the circle’s radius, involves the value p, which is approximately 3.14159. C++ supports such non-integer numbers, and they are called floating-point numbers. The name comes from the fact that during mathematical calculations the decimal point can move or “float” to various positions within the number to maintain the proper number of significant digits. The types float and double represent different types of floating-point numbers. - Haqiqiy tipli o’zgaruvchilar
- Many computational tasks require numbers that have fractional parts. For example, the formula from mathematics to compute the area of a circle given the circle’s radius, involves the value p, which is approximately 3.14159. C++ supports such non-integer numbers, and they are called floating-point numbers. The name comes from the fact that during mathematical calculations the decimal point can move or “float” to various positions within the number to maintain the proper number of significant digits. The types float and double represent different types of floating-point numbers.
- KONSTANTALAR. (CONSTANTS)
- Konstanta bu o’zgartirish mumkin bo’lmagan qiymatdir. C++ tilida besh turdagi konstantalar ishlatilishi mumkin: butun sonlar, haqiqiy sonlar, simvollar, sanovchi konstantalar va nul ko’rsatkich.
- 1. Ma’lumotlarning butun son turi.
- 2. Ma’lumotlarning haqiqiy son turi:
- 66. ,0 .12 , 3.14F 1.12e-12
- 3. Simvolli konstanta.
- ‘x’,’*’,’\012’,’\0’,’\n’
- Sanovchi konstanta.
- enum{one=1,two=2,three=3};
- Nul ko’rsatkich.
- NULL- ko’rsatkich yagona arifmetik bulmagan konstantadir.
- In Listing 3.9 (scientificnotation.cpp), Avogadro’s number and the speed of light are scientific constants;
- that is, to the degree of precision to which they have been measured and/or calculated, they do not vary. C ++ supports named constants. Constants are declared like variables with the addition of the const keyword:
- const double PI = 3.14159;
- Quyidagi jadvalda konstantalar chegaralari va mos tiplari ko’rsatilgan:
- Ko'p dasturlar ijro davomida arifmetik amallarni bajaradi. C++ dagi amallar quyidagi jadvalda berilgan.
- Misol. k = m * 5 + 7 % n / (9 + x); Birinchi bo'lib m * 5 hisoblanadi. Keyin 7 % n topiladi va qoldiq (9 + x) ga bo'linadi.
- Chiqqan javob esa m * 5 ning javobiga qo'shiladi. Qisqasini aytsak, amallar matematikadagi kabi. Lekin biz o'qishni osonlashtirish uchun va hato qilish ehtimolini kamaytirish maqsadida qavslarni kengroq ishlatishimiz mumkin. Yuqoridagi misolimiz quyidagi ko'rinishga ega bo'ladi.
- k = ( m * 5 ) + ( ( 7 % n ) / ( 9 + x ) );
Do'stlaringiz bilan baham: |