According the books, the variations of type integer occupy more or less bytes of memory, depending on the architecture, however the type unsigned short values can get up to 65 535, since the type unsigned long 4 294 967 295.
So far so good, but when we think of the format placeholders, we can see which variations of int type like short and long have your own format placeholders; %hd
and %ld
, respectively.
This way we can know how many bytes will be reserved for this types, because we have we are aware that we are using explicitly the data types, however, for unsigned short and unsigned long types just there a single format placeholder: %u
.
For me this means that I have no control about the number that will be set in this variable, I want mean, I must declare the variable like unsigned and the compiler will interpret if he number belongs to range of unsigned short or unsigned long.
What is the correct form of to declare variables of this types?
unsigned short <identifier_variable>;
unsigned short int <identifier_variable>;
or just:
unsigned <identifier_variable>;
and if the number belongs to range of the unsigned short type will reserve 2 bytes
for this variable, otherwise if the number assigned belong to unsigned long type all will work normally and the number of bytes reseved for this variable will be 4 bytes
.
Then, how I must doing this declarations and is there another format placeholders that I can't find in the GNU documentation?
C
orC++
? – Elliott Frisch Jan 7 '14 at 21:31unsigned
is same asunsigned int
,unsigned short
is same asunsigned short int
– Bryan Chen Jan 7 '14 at 21:31