Feb 7, 2012 at 9:44pm UTC
by default when i declare a variable like so
int variable;
by default does that variable come as a signed or unsigned variable? and does the same apply with any other Datatype other than just int?
Feb 7, 2012 at 9:53pm UTC
It depends on the settings you have set in your compiler, but on default settings a standard compliant compiler will treat it as signed.
The uses for signed variables are few and far between, by the way.
On a side note, these:
1 2 3
unsigned int u;
signed int s;
int i;
are the same as these respectively:
1 2 3
unsigned u;
signed s;
signed i;
Both will compile and run exactly the same way. So you can save yourself some typing :)
Last edited on Feb 7, 2012 at 9:55pm UTC
Feb 7, 2012 at 11:33pm UTC
All compilers I've used have been signed default, and I can't imagine it any other way. Just know, with signed you lose a bit of range on your number (bit as in binary digit) which essentially is half your range. So, if you're doing calculations that will never be negative, then I'd use unsigned.
Feb 7, 2012 at 11:53pm UTC
char can be unsigned or signed depending on compiler.
Feb 8, 2012 at 1:49am UTC
Some compilers let you specify default signed or unsigned for ALL types, as does mine ;)