In C++, I can declare a variable as either an unsigned short or an unsigned char (with 2 bytes) as shown below. However, is there any differences?
unsigned short p;
unsigned char q[2];
In C++, I can declare a variable as either an unsigned short or an unsigned char (with 2 bytes) as shown below. However, is there any differences?
unsigned short p;
unsigned char q[2];
Differences:
short
is platform dependent.char
array has no significant byte ordering.char
array may not be allocated on one of the same alignment boundaries as a short
.short
may be casted to a char
array so that it may be evaluated as an array of bytes, but the reverse is not allowed.