gdb を使用してコードをデバッグすると、頭痛の種になる問題が発生します。これが私のコード スニペットです。
int getMaxProfits( int *boards, int length, int consecutive )
{
int optBoards[length+3][length+3];
memset(optBoards, 0, sizeof( optBoards ) );
for( int i = length -1; i >= 0; i-- )
{
for( int j = i; j <= length - 1; j++ )
{
if( j == i )
{
optBoards[i][j] = boards[j];
}
else if( j - i < consecutive )
{
optBoards[i][j] = boards[j] + optBoards[i][j-1];
}
.....
2次元配列「optBoards」の全要素を出力しようとしたところ
p optBoards
思ったほど簡単ではないことがわかりました。
$1 = 0x7fff5fbff330
メモリアドレスのように見えるので、試しました
p optBoards[0][0]
私は得た
Cannot perform pointer math on incomplete types, try casting to a known type, or void *.
私は努力し続けます
ptype optBoards
私が見た
type = int [][0]
optBoards は 1 次元配列を指すポインターである必要があると思います。そのため、もう一度試しました。
p (int[][0])(*optBoards)[0]
またメモリーアドレスを取得しました
$2 = 0x7fff5fbff330
希望を見つけて再挑戦しました
p (int[][0])*((*optBoards)[0])
今、私は大きな0を取得します
$3 = 0x0
私はすでに必要な値を取得していると思っていましたが、後で for ループに入った後にわかりました。私は失われたと感じます。
この 2 次元配列の正しい値を出力するにはどうすればよいですか?
あなたの助けをいただければ幸いです。