• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

pointer value

i have a structure:

struct iorb_node {
   int *hook;

i want to set an integer value for hook (say for example, 2).  how do i do this correctly??
and once set, how would i access that value?
1 Solution
An integer can be converted to a pointer, so you can just code

someiorb_node.hook = 2;

You can access the value just by referring to the hook member, as in someiorb_node.hook.

Unless you are coding for a tiny embedded system with no operating system, it would be very unusual to do this kind of conversion.  Most operating systems are unlikely to let you access memory through a pointer with a value of 2, and the language definition makes no guarantees about what these operations will do.

I took your question literally, but maybe you wanted to work with the number the hook pointer addresses, not the pointer itself.  In that case, you need to use the dereferencing operator *, as in:

*(someiorb_node.hook) = 2;

if (*(someiorb_node.hook) == 2)

rawdribAuthor Commented:
it is for an operating system device modules implimentation, thanks for your help

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now