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 6176933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:11:12+00:00 2026-05-24T00:11:12+00:00

So let us say I have an array: int a[3] = { 1, 2,

  • 0

So let us say I have an array:

int a[3] = { 1, 2, 3 };

Now if I were to check the type of ‘a’, on my machine I get:

cout<<typeid(a).name(); // prints 'A3_i'

Now if I take the address of ‘a’, then dereference that address, the type does not change (which I really like, because in my mind ‘taking the address’ and ‘dereferencing’ are inverse operations):

cout<<typeid(*&a).name(); // also prints 'A3_i'

However if I dereference ‘a’ first, then take the address of that, the type does change (which I admit I have a hard time not liking, because when I dereferenced the array I should get an int, and when I take the address of that int, I should get a pointer-to-int, and it turns out I do):

cout<<typeid(&*a).name(); // prints 'Pi'

So here are my two questions:

1) Once an array-type has decayed into a pointer-type, is there anyway to get it back to an array-type?

I tried the obvious strategy of casting-like-you-just-don’t-care:

cout<<typeid( (int[3]) &*a).name(); // does not compile
// "error: ISO C++ forbids casting to an array type `int [3]'"

Is there another cast that would work? Or it is this type of conversion strictly off-limits?

2) Whether or not you can ever get back to the array-type, exactly what information is sliced and lost in the decay-to-pointer proccess?

I understand that a pointer-type and an array-type are not equivalent. I assume that the array-type is a strict superset of the information stored in the pointer-type. Does this sound right?

I have read in other questions that the extra information in the array-type is: knowledge of whether or not the array is on the stack, and also its size (it must know the size of the array somehow, because it is part of the type, right?). Is there any other information hidden in the array-type?

  • 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-24T00:11:13+00:00Added an answer on May 24, 2026 at 12:11 am

    I’m not sure if this is quite what you’re looking for, but you can use typecasting to get back an object with the same type as the original array. The idea is to use the little-known types pointer-to-array and reference-to-array to recover the information. For example:

    char arr[137];
    cout << sizeof(arr) << endl; // Prints 137
    cout << sizeof(arr[0]) << endl; // Prints 1
    cout << sizeof(&arr[0]) << endl; // Prints 4 (on my system)
    cout << sizeof(*&arr[0]) << endl; // Prints 1
    cout << sizeof((char (&) [137]) *&arr[0]) << endl; // Prints 137
    

    The idea is that we typecast the reference created by using *&arr[0] to type char (&)[137], a reference to an array of 137 characters. Now that the reference has this type, the sizeof operator knows that it should print 137, since the size of an array of 137 characters is indeed 137.

    However, this only works if you typecast to the correct type! For example, this is perfectly legal:

    char arr[137];
    cout << sizeof((char (&) [42]) *&arr[0]) << endl; // Prints 42
    

    So you can recover the information, but you can easily get that information wrong and lead to a case where you’ve recovered the incorrect information.

    Again, I’m not sure if this is what you were looking for, but it shows that you can indeed use casting to get back the array size information.

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

Sidebar

Related Questions

Let's say I have this array int[] anArray = { 100, 200, 300}; Now,
Let's say I have a C# variable and array: int variable_1 = 1; int[3]
OK let's say I have this array: public int[][] loadBoard(int map) { if (map
Let say I have a multi-dimensional array like int a[10][10] int b[10][10] void arrayCopy(int*
Let's say I have a 2D array: int[][] a = new int[4][3]; populated such
Let's say we have an array defined as a global variable. int array[] =
Let's say I have an array: int array[][] = {{1, 2, 3}, {2, 5,
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
Let's say I have two arrays: int ArrayA[] = {5, 17, 150, 230, 285};
Let say I have an array like: Array ( [0] => Array ( [Data]

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.