Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Why doesn't this code work at making a 2D array pointers in c++? The compiler complains about the second line not being a modifiable l-value.
int* g[2][2]; g[0] = new (int*)[2];
g
The type of g[0] is int* [2], i.e. it's an array. You cannot assign to an array.
g[0]
int* [2]
It's not clear what you're trying to achieve, so I can't offer a solution. If you clarify your question, I may be able to do better.
Add a comment
The first line is all you need to create an array of 2 arrays of pointers to int.
int
The reason you can't assign a new value to g[0] is because g[0] itself is an array, and you can't assign a new value to an array, only its elements.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
g???