Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand an array while debugging in visual studio code

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.

like image 606
debanka Avatar asked Jan 31 '26 02:01

debanka


1 Answers

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
like image 173
Mariano Burich Avatar answered Feb 02 '26 15:02

Mariano Burich