A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

Address to integer in C

  • This Question is Open
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I need help converting an address of a variable to an integer value. What I tried so far was casting the address as so: (int)(&variable). While it works, I want to find another way to do this without it giving a warning.

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    My guess is that `int` is not large enough to hold the value of the address, so you should use a sufficiently large data type like `uintptr_t`. You might be able to cast that to `int` without warning, but I don't know why you need to use an `int` in the first place.

  3. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    &variable is an unsigned integer by itself. If you have a 64bit machine ( you can put more than 4GB of RAM in it ), it may be too large for the C int data type which is usually a signed 32bit integer ( the 31st bit is used for the sign so the maximum value is a little over 2 billion ). I believe that an unsigned long int data type will handle an address fine.

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.