for example both short and unsigend short take 2 bytes of memory and from 0 to 65535 or from -32768 to 32767. so if both types take up 2 bytes of memory, how does the computer realize one is signed and the other is unsigend?
for example both short and unsigend short take 2 bytes of memory and from 0 to 65535 or from -32768 to 32767. so if both types take up 2 bytes of memory, how does the computer realize one is signed and the other is unsigend?
You, the programmer, told the compiler to use the proper type for the variables in question.how does the computer realize one is signed and the other is unsigend?
Jim
To illustrate @jimblumberg's response please see this demo program:
I don't know your knowledge or experience with the C Programming Language, but perhaps you should read my response to a previous posting.Code:#include <stdio.h> int main(void) { short svar = -1234; // short signed integer unsigned short uvar = 10; // unsigned short integer printf("The sizeof a signed short is %zu, and the value is %d\n", sizeof(svar), svar); printf("The sizeof an unsigned short is %zu, and the value is %d\n", sizeof(uvar), uvar); return 0; }