question about signed/unsigned

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?

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
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.
char can be unsigned or signed depending on compiler.
Some compilers let you specify default signed or unsigned for ALL types, as does mine ;)
Some compilers let you specify default signed or unsigned for ALL types, as does mine ;)

Yes but that is just an non-standard extension. The standard says that short, int, long and long long are signed.
Topic archived. No new replies allowed.