Visual Studio doesn't show full array when when dynamically creating array of pointers
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
My code:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
}
What I want to happen is that pptr
now points to the beginning of an array of 5 pointers that each point to the beginning of an array of 5 characters.
I put a breakpoint at the end of the main function and added pptr
to watch, and it only stores one pointer. Why does this happen and how do I do it correctly?
c++ visual-studio pointers debugging
add a comment |
My code:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
}
What I want to happen is that pptr
now points to the beginning of an array of 5 pointers that each point to the beginning of an array of 5 characters.
I put a breakpoint at the end of the main function and added pptr
to watch, and it only stores one pointer. Why does this happen and how do I do it correctly?
c++ visual-studio pointers debugging
1
You said you wantedpptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.
– Galik
Jan 4 at 14:39
1
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44
add a comment |
My code:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
}
What I want to happen is that pptr
now points to the beginning of an array of 5 pointers that each point to the beginning of an array of 5 characters.
I put a breakpoint at the end of the main function and added pptr
to watch, and it only stores one pointer. Why does this happen and how do I do it correctly?
c++ visual-studio pointers debugging
My code:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
}
What I want to happen is that pptr
now points to the beginning of an array of 5 pointers that each point to the beginning of an array of 5 characters.
I put a breakpoint at the end of the main function and added pptr
to watch, and it only stores one pointer. Why does this happen and how do I do it correctly?
c++ visual-studio pointers debugging
c++ visual-studio pointers debugging
edited Jan 4 at 14:54


drescherjm
6,58923553
6,58923553
asked Jan 4 at 14:30
Viktor AxénViktor Axén
385
385
1
You said you wantedpptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.
– Galik
Jan 4 at 14:39
1
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44
add a comment |
1
You said you wantedpptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.
– Galik
Jan 4 at 14:39
1
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44
1
1
You said you wanted
pptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.– Galik
Jan 4 at 14:39
You said you wanted
pptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.– Galik
Jan 4 at 14:39
1
1
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44
add a comment |
3 Answers
3
active
oldest
votes
This is the default knowledge of your pointer type in Visual Studio. You indicate in the code that char** pptr
is a pointer, but it cannot know how big.
To fix this, you can add a watch on pptr[0]
, and then you can specify that it has a "size" of 5 by changing it to pptr[0],5
. Also, if the size is variable you can do "ptr[0],[size]" where size is an expression that evaluates to the number of elements to show.
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, sincepptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.
– François Andrieux
Jan 4 at 14:55
Yes, the,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!
– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to bechar*[5]
being c++ as I proposed ? (I do not use Visual Studio)
– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have areinterprect_cast
in the expression as well (I think).
– Matthieu Brucher
Jan 4 at 14:59
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5char*
which I think is writtenchar*(&)[5]
. Edit : The watch expression(char*(&)[5])(*pptr)
will give youpptr
as an array of 5char*
. Edit 2 : Thoughpptr,5
is still a way nicer way of doing it.
– François Andrieux
Jan 4 at 15:08
|
show 1 more comment
Your program does what you want, but the debugger cannot know the number of elements, it just know it is a pointer, so it write the contains of that pointer.
I don't know what debugger you use, but probably when you display the values you can modify char**
by char*[5]` to see all
add a comment |
// #include "pch.h"
#include <iostream>
using namespace std;
int main(){
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
for(int i=0;i<5;i++){
char ch='A';
pptr[0][i]=ch;
}
for(int i=0;i<5;i++){
cout<<pptr[0][i]<<" ";
}
}
Now the pptr[0] that is a pointer is pointing to an array of characters. Hope that it helps.
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040892%2fvisual-studio-doesnt-show-full-array-when-when-dynamically-creating-array-of-po%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is the default knowledge of your pointer type in Visual Studio. You indicate in the code that char** pptr
is a pointer, but it cannot know how big.
To fix this, you can add a watch on pptr[0]
, and then you can specify that it has a "size" of 5 by changing it to pptr[0],5
. Also, if the size is variable you can do "ptr[0],[size]" where size is an expression that evaluates to the number of elements to show.
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, sincepptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.
– François Andrieux
Jan 4 at 14:55
Yes, the,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!
– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to bechar*[5]
being c++ as I proposed ? (I do not use Visual Studio)
– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have areinterprect_cast
in the expression as well (I think).
– Matthieu Brucher
Jan 4 at 14:59
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5char*
which I think is writtenchar*(&)[5]
. Edit : The watch expression(char*(&)[5])(*pptr)
will give youpptr
as an array of 5char*
. Edit 2 : Thoughpptr,5
is still a way nicer way of doing it.
– François Andrieux
Jan 4 at 15:08
|
show 1 more comment
This is the default knowledge of your pointer type in Visual Studio. You indicate in the code that char** pptr
is a pointer, but it cannot know how big.
To fix this, you can add a watch on pptr[0]
, and then you can specify that it has a "size" of 5 by changing it to pptr[0],5
. Also, if the size is variable you can do "ptr[0],[size]" where size is an expression that evaluates to the number of elements to show.
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, sincepptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.
– François Andrieux
Jan 4 at 14:55
Yes, the,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!
– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to bechar*[5]
being c++ as I proposed ? (I do not use Visual Studio)
– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have areinterprect_cast
in the expression as well (I think).
– Matthieu Brucher
Jan 4 at 14:59
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5char*
which I think is writtenchar*(&)[5]
. Edit : The watch expression(char*(&)[5])(*pptr)
will give youpptr
as an array of 5char*
. Edit 2 : Thoughpptr,5
is still a way nicer way of doing it.
– François Andrieux
Jan 4 at 15:08
|
show 1 more comment
This is the default knowledge of your pointer type in Visual Studio. You indicate in the code that char** pptr
is a pointer, but it cannot know how big.
To fix this, you can add a watch on pptr[0]
, and then you can specify that it has a "size" of 5 by changing it to pptr[0],5
. Also, if the size is variable you can do "ptr[0],[size]" where size is an expression that evaluates to the number of elements to show.
This is the default knowledge of your pointer type in Visual Studio. You indicate in the code that char** pptr
is a pointer, but it cannot know how big.
To fix this, you can add a watch on pptr[0]
, and then you can specify that it has a "size" of 5 by changing it to pptr[0],5
. Also, if the size is variable you can do "ptr[0],[size]" where size is an expression that evaluates to the number of elements to show.
edited Jan 4 at 15:02
SoronelHaetir
7,1831514
7,1831514
answered Jan 4 at 14:37
Matthieu BrucherMatthieu Brucher
17.8k52445
17.8k52445
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, sincepptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.
– François Andrieux
Jan 4 at 14:55
Yes, the,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!
– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to bechar*[5]
being c++ as I proposed ? (I do not use Visual Studio)
– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have areinterprect_cast
in the expression as well (I think).
– Matthieu Brucher
Jan 4 at 14:59
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5char*
which I think is writtenchar*(&)[5]
. Edit : The watch expression(char*(&)[5])(*pptr)
will give youpptr
as an array of 5char*
. Edit 2 : Thoughpptr,5
is still a way nicer way of doing it.
– François Andrieux
Jan 4 at 15:08
|
show 1 more comment
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, sincepptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.
– François Andrieux
Jan 4 at 14:55
Yes, the,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!
– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to bechar*[5]
being c++ as I proposed ? (I do not use Visual Studio)
– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have areinterprect_cast
in the expression as well (I think).
– Matthieu Brucher
Jan 4 at 14:59
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5char*
which I think is writtenchar*(&)[5]
. Edit : The watch expression(char*(&)[5])(*pptr)
will give youpptr
as an array of 5char*
. Edit 2 : Thoughpptr,5
is still a way nicer way of doing it.
– François Andrieux
Jan 4 at 15:08
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, since
pptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.– François Andrieux
Jan 4 at 14:55
That's an interesting solution to an annoying problem, I'll try it out in the future. Though I'm surprised, since
pptr[0],5
has a distinct meaning in c++. It seems inconsistent for the debugger to arbitrarily interpret certain operators differently when it treats most operators the same way the language does.– François Andrieux
Jan 4 at 14:55
Yes, the
,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!– Matthieu Brucher
Jan 4 at 14:57
Yes, the
,
is specific to the debugger watch variable. I'm not sure it works with a comma operator as the expression. Probably triggeres a bunch of errors somewhere!– Matthieu Brucher
Jan 4 at 14:57
yes is strange, is it not possible to change the type of the element to display to be
char*[5]
being c++ as I proposed ? (I do not use Visual Studio)– bruno
Jan 4 at 14:59
yes is strange, is it not possible to change the type of the element to display to be
char*[5]
being c++ as I proposed ? (I do not use Visual Studio)– bruno
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have a
reinterprect_cast
in the expression as well (I think).– Matthieu Brucher
Jan 4 at 14:59
No, it only displays the type as VS understands it. But then, you can always have a
reinterprect_cast
in the expression as well (I think).– Matthieu Brucher
Jan 4 at 14:59
1
1
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5
char*
which I think is written char*(&)[5]
. Edit : The watch expression (char*(&)[5])(*pptr)
will give you pptr
as an array of 5 char*
. Edit 2 : Though pptr,5
is still a way nicer way of doing it.– François Andrieux
Jan 4 at 15:08
Yes, you should be able to dereference the pointer and cast it to a reference to an array of 5
char*
which I think is written char*(&)[5]
. Edit : The watch expression (char*(&)[5])(*pptr)
will give you pptr
as an array of 5 char*
. Edit 2 : Though pptr,5
is still a way nicer way of doing it.– François Andrieux
Jan 4 at 15:08
|
show 1 more comment
Your program does what you want, but the debugger cannot know the number of elements, it just know it is a pointer, so it write the contains of that pointer.
I don't know what debugger you use, but probably when you display the values you can modify char**
by char*[5]` to see all
add a comment |
Your program does what you want, but the debugger cannot know the number of elements, it just know it is a pointer, so it write the contains of that pointer.
I don't know what debugger you use, but probably when you display the values you can modify char**
by char*[5]` to see all
add a comment |
Your program does what you want, but the debugger cannot know the number of elements, it just know it is a pointer, so it write the contains of that pointer.
I don't know what debugger you use, but probably when you display the values you can modify char**
by char*[5]` to see all
Your program does what you want, but the debugger cannot know the number of elements, it just know it is a pointer, so it write the contains of that pointer.
I don't know what debugger you use, but probably when you display the values you can modify char**
by char*[5]` to see all
answered Jan 4 at 14:34


brunobruno
14.4k31426
14.4k31426
add a comment |
add a comment |
// #include "pch.h"
#include <iostream>
using namespace std;
int main(){
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
for(int i=0;i<5;i++){
char ch='A';
pptr[0][i]=ch;
}
for(int i=0;i<5;i++){
cout<<pptr[0][i]<<" ";
}
}
Now the pptr[0] that is a pointer is pointing to an array of characters. Hope that it helps.
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
add a comment |
// #include "pch.h"
#include <iostream>
using namespace std;
int main(){
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
for(int i=0;i<5;i++){
char ch='A';
pptr[0][i]=ch;
}
for(int i=0;i<5;i++){
cout<<pptr[0][i]<<" ";
}
}
Now the pptr[0] that is a pointer is pointing to an array of characters. Hope that it helps.
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
add a comment |
// #include "pch.h"
#include <iostream>
using namespace std;
int main(){
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
for(int i=0;i<5;i++){
char ch='A';
pptr[0][i]=ch;
}
for(int i=0;i<5;i++){
cout<<pptr[0][i]<<" ";
}
}
Now the pptr[0] that is a pointer is pointing to an array of characters. Hope that it helps.
// #include "pch.h"
#include <iostream>
using namespace std;
int main(){
char** pptr = new char*[5];
for (int i = 0; i < 5; i++)
pptr[i] = new char[5];
for(int i=0;i<5;i++){
char ch='A';
pptr[0][i]=ch;
}
for(int i=0;i<5;i++){
cout<<pptr[0][i]<<" ";
}
}
Now the pptr[0] that is a pointer is pointing to an array of characters. Hope that it helps.
edited Jan 4 at 14:43


François Andrieux
16.7k32950
16.7k32950
answered Jan 4 at 14:40
Prabhakar JhaPrabhakar Jha
61
61
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
add a comment |
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
4
4
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
the problem doesn't concern the code but what the debugger shows by default
– bruno
Jan 4 at 14:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040892%2fvisual-studio-doesnt-show-full-array-when-when-dynamically-creating-array-of-po%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You said you wanted
pptr
to point to the beginning of an array of pointers... the beginning of an array is indeed one pointer - the first one in the array. The other pointers come later in the same array.– Galik
Jan 4 at 14:39
1
Please next time reduce the picture to its interesting part to not have that large white margin ;-)
– bruno
Jan 4 at 14:44