Is there anything such as an unsigned int*
which is different from int*
. I know that unsigned
has a higher range of values. Still, can't int*
even point to any unsigned int
?
A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295].
The term "unsigned" in computer programming indicates a variable that can hold only positive numbers. The term "signed" in computer code indicates that a variable can hold negative and positive values.
An int is signed by default, meaning it can represent both positive and negative values. An unsigned is an integer that can never be negative.
normal = (unsigned)pointer; This would result in the variable normal containing its own address. I will consider shortly whether this code would actually work or not. In broad terms, most of the time, code should: perform the required function.
int *
and unsigned int *
are two different pointer types that are not compatible types. They are also pointers to incompatible types. For the definition of compatible types, please refer to § 6.2.7 in the C Standard (C11).
Being pointers to incompatible types means that for example that this:
unsigned int a = 42; int *p = &a; // &a is of type unsigned int *
is not valid (the constraints of the assignment operator are violated).
Another difference between the two types is as for most other pointer types (although unlikely here) there is no guarantee from C they have the same size or the same representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With