VS Studio中调试C程序(MinGW环境):如何显示完整数组内容?
I’ve run into this exact headache when using MinGW with Visual Studio’s debugger—here are practical fixes to let you see the full contents of your A[4] array:
1. Explicitly Define Array Range in the Watch Window
When you pass an array to a function like quickSort, it decays to a pointer, so the debugger only shows the first element by default. To fix this:
- Manually add a watch entry like
A,4(the comma + array length tells the debugger to display all 4 elements) - Alternatively, use
A[0..3]to specify the exact index range you want to inspect
This should immediately show you all values {10, 5, 7, 1} in the Watch window.
2. Correct GDB Command Syntax for Debug Console
The p A command only prints the pointer address when dealing with a decayed array pointer. Try these GDB commands instead:
p *A@4: This tells GDB to print 4 consecutive elements starting at the pointerAp A[0],p A[1], etc., to print individual elements if you don’t need the full array at once
Bonus: Fix Your QuickSort Logic (Avoid Future Debugging Pain)
While not directly related to your array display issue, I spotted a critical bug in your quickSort function that will break sorting entirely:
quickSort(A, p, r); // first half quickSort(A, q + 1, r); // second half
The first recursive call should target the left partition: quickSort(A, p, q-1); Right now you’re re-sorting the full range p to r every time, which will cause infinite recursion or incorrect results.
内容的提问来源于stack exchange,提问作者Katie Melosto

