Reputation: 1
I have a C code that I'm analizing and there is something like this:
variable = (unsigned long)rx;
If rx
is an array of hex numbers and variable is of unsigned long
, what will variable hold? The first element in unsigned long
format?
Upvotes: 0
Views: 64
Reputation: 49433
Since arrays decay to pointers anytime you use an array's name, and do not deference it, you're going to get an address.
thus:
variable = (unsigned long)rx;
Will assign rx[]
's address to variable
as an unsigned long value. Whereas this:
variable = (unsigned long)*rx;
or this:
variable = (unsigned long)rx[0];
will give you the value of the first element of rx[]
(note that the syntax rx[0]
is basically saying take the base address of rx
+ a 0
offset, dereference it and return the result)
Upvotes: 1
Reputation: 409216
Remember that arrays decays to pointers. So what will happen is that the cast will convert the pointer (i.e. memory address) to an unsigned long
and assign that to variable
.
Upvotes: 1