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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:17:41+00:00 2026-05-16T15:17:41+00:00

This is probably a stupid question, but I don’t understand why this works: int**

  • 0

This is probably a stupid question, but I don’t understand why this works:

 int** test = new int*[7];

 int x = 7;
 *(test+1) = &x;

 cout << (**(test+1));

test is a pointer to a pointer right? The second pointer points to the array, right?
In my understand I would need to dereference the “test” pointer first to get to the pointer that has the array.

(*test) // Now I have int*
*((*test) + 1) // to access the first element.

Where is my faulty thinking?

  • 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-16T15:17:41+00:00Added an answer on May 16, 2026 at 3:17 pm

    Is your misunderstanding that you think you have created a pointer to an array of 7 int? You haven’t. You actually have created an array of 7 pointers to int. So there is no “second pointer” here that would point to an array. There is just one pointer that points to the first of the 7 pointers (test).

    And with *test you get that first pointer which you haven’t initialized yet, though. If you would add 1 to that, you would add 1 to some random address. But if you add 1 to test you get a pointer that points to the second pointer of the array. And dererencing that you get that second pointer, which you did initialize.


    What you describe would be achieved by a different syntax

    typedef int array[7];
    array* test = new int[1][7];
    
    // Note: "test" is a pointer to an array of int. 
    // There are already 7 integers! You cannot make it
    // point to an int somehow. 
    *(*test + 1) = 7;
    
    int *p1 = *test
    int i1 = *(p1 + 1); // i1 is 7, second element of the int[7]
    
    delete[] test;
    

    Without using the typedef, this looks like the following

    int(*test)[7] = new int[1][7];
    

    That is, you have created a one-element array, where the element-type of that is a 7-element array of int. new gives you a pointer back to that array. Note that the parenthesis is important: The * has less precedence than the [7], so otherwise this would be taken as an array of 7 pointer to integers.

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

Sidebar

Related Questions

This is probably a stupid question. I don't know anything about Web Service but
This is probably a really stupid MSBuild question but if I have <ItemGroup> <Dll
This is probably a really stupid newbie-sounding question to you developer type people, but
Probably a stupid question, but I'm quite new to the whole get-and-set-property-kind of programming;
I'm new to Java/Eclipse/Android, so this is probably an easy (if not stupid) question:
This is probably a stupid question but I need to ask it because I've
This is probably a really stupid question but I can't figure this out. I
I know it is probably a stupid question, but I am new to OOP
This is probably a stupid question but will ask anyway sine I have no
This is probably a stupid question but, I have a method I use to

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.