pointer value

Posted on 2004-11-09
Last Modified: 2010-04-15
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?
Question by:rawdrib
    LVL 15

    Accepted 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)


    Author Comment

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

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now