Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:44+00:00 2026-05-27T22:42:44+00:00

For example: int* x = new int; int y = reinterpret_cast<int>(x); y now holds

  • 0

For example:

int* x = new int;
int y = reinterpret_cast<int>(x);

y now holds the integer value of the memory address of variable x.
Variable y is of size int. Will that int size always be large enough to store the converted memory address of ANY TYPE being converted to int?

EDIT:
Or is safer to use long int to avoid a possible loss of data?

EDIT 2: Sorry people, to make this question more understandable the thing I want to find out here is the size of returned HEX value as a number, not size of int nor size of pointer to int but plain hex value. I need to get that value in in human-readable notation. That’s why I’m using reinterpret_cast to convert that memory HEX value to DEC value. But to store the value safely I also need to fing out into what kind of variable to it: int, long – what type is big enough?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:42:44+00:00Added an answer on May 27, 2026 at 10:42 pm

    No, that’s not safe. There’s no guarantee sizeof(int) == sizeof(int*)

    On a 64 bit platform you’re almost guaranteed that it’s not.

    As for the “hexadecimal value” … I’m not sure what you’re talking about. If you’re talking about the textual representation of the pointer in hexadecimal … you’d need a string.

    Edit to try and help the OP based on comments:

    Because computers don’t work in hex. I don’t know how else to explain it. An int stores some amount of bits (binary), as does a long. Hexadecimal is a textual representation of those bits (specifically, the base16 representation). strings are used for textual representations of values. If you need a hexadecimal representation of a pointer, you would need to convert that pointer to text (hex).

    Here’s a c++ example of how you would do that:

    test.cpp

    #include <string>
    #include <iostream>
    #include <sstream>
    
    int main()
    {
    
        int *p; // declare a pointer to an int. 
        std::ostringstream oss; // create a stringstream
        std::string s; // create a string
    
        // this takes the value of p (the memory address), converts it to 
        // the hexadecimal textual representation, and puts it in the stream
        oss << std::hex << p;
    
        // Get a std::string from the stream
        s = oss.str();
    
        // Display the string
        std::cout << s << std::endl;
    
    }
    

    Sample output:

    roach$ g++ -o test test.cpp
    roach$ ./test
    0x7fff68e07730

    It’s worth noting that the same thing is needed when you want to see the base10 (decimal) representation of a number – you have to convert it to a string. Everything in memory is stored in binary (base2)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following example: int size = 10, *kk = new int[size]; for (int
I have string value and Type of some variable (For example int and 32
There is an int[] variable , for example private int[3] tInt = new int[]{6,9,4};
Example int *ptr; *ptr = 1000; can I catch memory access violation exception using
So I have 2 functions that both have similar arguments void example(int a, int
If you are not reading a value but assigning a value for example int
Take this example: int[] queryValues1 = new int[10] {0,1,2,3,4,5,6,7,8,9}; int[] queryValues2 = new int[100];
I have two arrays. For example: int[] Array1 = new[] {1, 2, 3, 4,
Consider this example: int[] a = new int[] {0,0}; ArrayList<int[]> b = new ArrayList<int[]>();
Example code: int a[] = new int[]{0, 1, 2, 3}; int result = 0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.