Regarding precision, Integer type of data can be declared as short or long.
In C, there are no limitations on how short or long must be long, but some rules apply:
§ short can’t be longer than int
§ int can't be longer than long
Altogether regarding distance, we can declare: short =< int =< long
Integer type of data also includes: char (when representing numeral, and not symbolic representation).
SIZE OF GENERAL DATA TYPES
Size of general types of data, more precise, amount of space which one variable of general data type uses in memory isn’t fixed. It depends of concrete implementation of translator program. Example of difference in interpretation can be seen by translator programs made by Borland which used 16 bits to save int variable, while Microsoft uses 32 bits to save variable int in memory.
Size of general types of data (according to MSDN Library for MS Visual C++ 6.0)
Type | Size |
char, unsigned char, signed char | 1 octet |
short, unsigned short | 2 octet |
int, unsigned int | 4 octet |
long, unsigned long | 4 octet |
float | 4 octet |
double | 8 octet |
long double | 8 (10) octet |
Dimensions of these types aren’t strictly regulated in C translator programs, what leaves programmer (person) use of operator sizeof, which returns size of wanted parameter in octets.
Operator sizeof can be also used to determine size of data types, along with possibility to determine size of certain variable type!
Example:
int var;
printf("%d",sizeof(char)); // prints 1
printf("%d",sizeof(var)); // prints 4 (on MSVisualC++ 6.0)
Display of Integers with forsign and without it
Qualificator signed (with foresign) marks that varable can save positive and negative number
Variable declared as unsigned (without foresign) can save only positive numbers, but it doubles our maximal positive number that can b saved compared to signed.
Example:
Display hexadecimal content of variable short which consists of -7.
710 = 1112
0000000000000111
1111111111111000 (complement)
+1
1
1111111111111001
F F F 9
Example:
Number 5 displayed in 16-bit registry:
| | | | | | | | | | | | | | | |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
| | | | | | | | | | | | | | | |
Number –5 displayed with method of double complement in 16-bit registry, where leading 1, can be considered as number’s foresign (+/-) (1 means the number is negative):
| | | | | | | | | | | | | | | |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
| | | | | | | | | | | | | | | |
If we take the same flow of binary digits, and save them in an integer variable without forsign, then the leading 1 is part of the number (NOT FORESIGN IN THIS CASE). In this way number 65531 is shown:
| | | | | | | | | | | | | | | |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
| | | | | | | | | | | | | | | |
It was well over 10 years ago when Borland compilers were 16-bit. An int is 32 bits on every compiler made for the x86 platform.
you might want to reconsider the structure of this somewhat. It would probably be a very good idea to have started with helloWorld some time ago. Since thus far in the tutorials you have not explained anything about C programming sytnax, and then suddenly you get
printf("%d",sizeof(char)); // print 1
the only part of which that you have explained is sizeof(char). If i were a newbie i'd be getting very confused right now....
i am a newbie and yes i am very confused right now,
im going straight to lesson 7, ooh rebellious!