14

This is my code, its a simple code block for permutation:

void arrange(char c[], int N, int start)
{
    if (start == N)
    {
        print(c, N);
        return;
    }
    for (int i = start; i < N; i++)
    {
        swap(c[start], c[i]);
        arrange(c, N, i + 1);
        swap(c[start], c[i]);
    }
}

int main(int argc, char const *argv[])
{
    char c[] = { 'A','B','C' };
    int N = (sizeof(c) / sizeof(char));
    arrange(c, N, 0);
    return 0;
}

Its not giving the output I expect and I wanted to debug this code. I wanted to observe the character swaps in the input array. But when I debug, the input array cannot be expanded.

3
  • 3
    In the watch window use c,10 or however many entries you want to display. Commented Oct 9, 2018 at 12:48
  • 1
    Alternatively, for simple chars, memory window shows exactly what you want. Commented Oct 9, 2018 at 12:49
  • 3
    Note that c in function arrange is not an array. It is just a pointer to char. Commented Oct 9, 2018 at 12:53

2 Answers 2

30

If you have an array t that is pointed to by p, like this:

double t[5] = {0,1,2,4.5,2.3};
double *p = t;

You can watch p on the debugger if you recast it. Just write on the watch window:

(double[5]) *p
Sign up to request clarification or add additional context in comments.

1 Comment

what if I debug C program, not a C++ program
24

When adding a beak point in arrange() then the c array shows it's address0x7fffffffdd15 like this:

Problem

To solve this on the bottom left you should see the WATCH section.
Add <your_array_name>, <array_length> like this:

enter image description here

Now in the watch section you should see your array like this:

enter image description here

2 Comments

Easiest way! BTW, where did you found this magic?
also interested. btw we can also limit the lower bounds of course by adding a index operator and then converting it back to a pointer, so *c[1],2 will return c[2] and c[3]

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.