Главная

lifwynnfoundation.org referral Language Basics Data species Integer varieties Char, Short, Int and also Long Types

 Char, Short, Int and Long Types Char, Short, Int and also Long TypescharThe char kind takes 1 byte of memory (8 bits) and allows expressing in the binary notation 2^8=256 values. The char kind can save both hopeful and an unfavorable values. The range of values is from -128 to 127.You are watching: How many bytes in a char cucharThe uchar integer form also rectal 1 byte that memory, as well as the char type, yet unlike the uchar is intended only for optimistic values. The minimum worth is zero, the maximum value is 255. The first letter u in the surname of the uchar type is the abbreviation for unsigned.shortThe dimension of the short kind is 2 bytes (16 bits) and, accordingly, it allows expressing the variety of values equal come 2 to the power 16: 2^16 = 65 536.Since the short form is a signed one, and also contains both positive and negative values, the variety of values is in between -32 768 and also 32 767.ushortThe unsigned short kind is the kind ushort, which also has a dimension of 2 bytes. The minimum worth is 0, the maximum worth is 65 535.intThe size of the int form is 4 bytes (32 bits). The minimal worth is -2 147 483 648, the maximal one is 2 147 483 647.uintThe unsigned integer type is uint. That takes 4 bytes of memory and enables expressing integers native 0 come 4 294 967 295.longulongExamples:charch=12;shortsh=-5000;intin=2445777;

Since the unsigned integer varieties are no designed because that storing an unfavorable values, the effort to set a an unfavorable value deserve to lead to unexpected consequences. Together a straightforward script will cause an boundless loop:

 //---InfiniteloopvoidOnStart()ucharu_ch;for(charch=-128;chu_ch=ch;Print("ch=",ch,"u_ch=",u_ch);

The exactly variant is:

 //---CorrectvariantvoidOnStart()ucharu_ch;for(charch=-128;chu_ch=ch;Print("ch=",ch,"u_ch=",u_ch);if(ch==127)break;

Result: