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

  • Home
  • SEARCH
  • 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 6124579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:08:57+00:00 2026-05-23T16:08:57+00:00

Suppose I have a byte[] array, I am wondering what I am really doing

  • 0

Suppose I have a byte[] array, I am wondering what I am really doing when I make a pointer to the array and then cast it to an int. When I dereference the said int pointer, I get a larger number in the case bellow: (code may have errors)

    byte[] bytes = new byte[100];
    bytes[0] = 1;
    bytes[1] = 2;
    bytes[2] = 3;
    bytes[3] = 4;


    fixed (byte* pMem = &bytes[0])
    {

    Debug.WriteLine("{0:x16}", (int)pMem);

    byte* pMemPlus1 = pMem + 1;
    Debug.WriteLine("{0:x8}", *pMemPlus1);

    byte* pMemPlus2 = pMem + 2;
    Debug.WriteLine("{0:x16}", *pMemPlus2);

    int* pArrayBase = (int*) pMem;
    Debug.WriteLine("{0:x8}", *pArrayBase);

    int* pArrayBasePlus1 = pArrayBase+1;
    Debug.WriteLine("{0:x8}", *pArrayBasePlus1;
    }   

Right so as expected, pMem, PMemPlus1 and PMemPlus2 dereference to 1,2 and 3. (int)pMem I take it is the value of the pointer (memory address).

When it is cast as an int pointer though, pArrayBase gives 4030201 and pArrayBasePlus1 gives the number 4. The latter makes sense because an int is 4 bytes long, right. But I don’t understand. the result when I just dereference the int-cast array pointer (pArrayBase). Any explanations? I might not understand the concept of casting properly.

  • 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-23T16:08:57+00:00Added an answer on May 23, 2026 at 4:08 pm

    Your memory is layed out something like the following:

    01 02 03 04 00 00 00 00
    

    pArrayBase is pointing to the four-byte integer at your array’s base address. Since integers are stored in little endian format, this results in the value 0x04030201. The interesting result is when you dereference pArrayBasePlus1. pArrayBasePlus1 is pointing to the four bytes following the first four. Unless you’ve left out some code, it looks like *pArrayBasePlus1 should be 0.

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

Sidebar

Related Questions

Suppose i have input array byte A[50]; i have put three diffrent data types
Suppose I have: unsafe { byte* start = GetStartLocation(); int something = start[4]; }
Suppose I have a Byte array and I use Encoding.ASCII.GetString() to convert the bytes
Suppose we have to create many small objects of byte array type. The size
Suppose I have a method like so: public byte[] GetThoseBytes() { using (System.IO.MemoryStream ms
Let's suppose I have a function: int f1(int x){ // some more or less
Using Java, I have a class which retrieves a webpage as a byte array.
Suppose you have a class with this constructor: public SomeObj(int x, int y) {
I have a byte array with a ~known binary sequence in it. I need
I am making C# windows application.In that application i have one byte array containing

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.