Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between unsigned and signed int pointer

Tags:

c

pointers

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?

like image 417
tomol Avatar asked Dec 23 '14 17:12

tomol


People also ask

What is difference between unsigned and signed integer?

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].

What is the difference between unsigned and signed?

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.

What is the difference between unsigned int and int?

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.

What is unsigned pointer in C?

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.


1 Answers

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.

like image 118
ouah Avatar answered Oct 21 '22 06:10

ouah