Is it legal to use "unsigned float"?
No, there is no such type.
I think floating point numbers always need sign.
It has nothing to do with whether or not floating point numbers "need"
a sign, it has to do with the arithmetic types defined by C++.
When i Checked with VC++ 6.0, i got following warning message only.
warning C4076: 'unsigned' : can not be used with type 'float'
The keyword 'unsigned' is not a modifier. Except for char, each
integer type in C++ (short, int, long) comes in two varieties, signed
and unsigned. For historical reasons there are three types of char,
signed, unsigned, and "plain". Each of these is a distinct and
different type. You can't pass a pointer to unsigned (char, short,
int, long) to a function declared to accept a pointer to signed (char,
short, int, long).
Other doubt is that,
decalre an unsgined int as below:
unsigned nNumber = 0;
Is there something wrong in doing like this.
No, there is nothing wrong with doing this. There are certain places
in C++ syntax where the keyword 'int' may be omitted and is inferred
by the compiler from context. Also with integer types other than
char, the keyword 'signed' may be omitted as it is always implied by
the absence of the keyword 'unsigned'.
There are two varieties of the "short" data type, their official names
are "short int" and "unsigned short int". But the following shortened
notations are allowed:
- "short" is equivalent to "signed short int"
- "signed short" is equivalent to "signed short int"
- "short int" is equivalent to "signed short int"
- "unsigned short" is equivalent to "unsigned short int"
There are two varieties of the "int" data type, "int" and "unsigned
int":
- "int" is equivalent to "signed int"
- "unsigned" (without 'char', 'short', or 'long') is equivalent to
"unsigned int"
There are two varieties of the "long" data type, "long int" and
"unsigned long int". The following shortened notions are allowed:
- "long" is equivalent to "signed long int"
- "signed long" is equivalent to "signed long int"
- "long int" is equivalent to "signed long int"
- "unsigned long" is equivalent to "unsigned long int"
Note there are no shortened notations available for the three
character types. They must be spelled out in full, "char", "signed
char", "unsigned char".
So "unsigned" by itself means "unsigned int". But "signed" by itself
is an error and means nothing.