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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:01:00+00:00 2026-06-06T15:01:00+00:00

When I try a test program with just these two lines char array[256]; char**

  • 0

When I try a test program with just these two lines

char array[256];
char** arrayPointer=&array;

I get the error

cannot convert from char*[256] to char**.

Yet if I do this:

char array[256];
char* temp=array;
char** arrayPointer=&temp;

I get no such complaint.

I figured that it was eclipse acting buggy (which my eclipase is acting funny right now) but when I tried to do a cast of the &array to char** for the function I ended up with unusual behavior and my debugger implying that the array isn’t being modified as it should.

PS. all of this was written by hand, forgive typos.

  • 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-06-06T15:01:01+00:00Added an answer on June 6, 2026 at 3:01 pm

    In C++, arrays and pointers are not the same thing. Arrays in many cases can implicitly be converted to a pointer, but array types and pointer types are different.

    In your case, the variable

    char array[256];
    

    has type char[256]. If you take its address by writing &array, you get a pointer to an array of 256 chars, which has type char (*)[256]. This is not the same a char**. This is actually a good thing. If you could do the conversion, what would happen if you did this?

    char array[256];
    char** ptrPtr = &array; // Not legal!
    *ptrPtr = new char[256];
    

    In this case, the third line would “reassign” array to point to a new array of 256 elements. However, array is not a pointer! This operation is meaningless.

    The reason you got a weird debugger error when writing

    char array[256];
    char** ptrPtr = (char**) &array; // Legal, but Bad Times!
    *ptrPtr = new char[256];
    

    is that the cast you’ve put in results in undefined behavior. You’re pretending that a pointer to an array of 256 actual char objects is really a pointer to a pointer to a char. This is a meaningless cast, so all bets are off when you do it.

    On the other hand, if you explicitly introduce a char* variable like this:

    char array[256];
    char* ptr = array;
    char** ptrPtr = &ptr;
    

    Then everything is fine. In the second line, you create a pointer (actual type char*) that points to the first element of array. In the third line, you create a pointer to that new pointer. If you then write

    *ptrPtr = new char[137];
    

    Then nothing bad happens; you’ve just changed where ptr was pointing, and didn’t destroy array.

    Hope this helps!

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

Sidebar

Related Questions

I'm creating a unit test to try out the servlet I just created. @Test
Im in /order/test When I try to /order/test?lala=test&baba=test public function action_test(){ echo var_dump($_GET); }
I was doing a little test to try Ruby's pty and I can't get
the code below gives compilation error when I try to create test t[2]; because
Whenever I try to test my code with JUnit, I receive a NullPointerException -
From the following snippet i try to test NewGlobalRef and try to make clsStr
I am doing the below test to try and learn more about LINQ to
i have problem with maven. When i try to compile test classes ( mvn
What test text do you try and type into your web forms to check
I try to create unit test cases to check my table values are correct

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.