【问题标题】:Error Debug Assertion Failed错误调试断言失败
【发布时间】:2014-01-07 08:12:18
【问题描述】:

我编码:

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>

void nhap(int **s, int line, int column)
{
int x;
srand((unsigned int)time(NULL));
for(int i=0; i<line; i++)
    for(int j=0; j<column; j++)
    {
        x=rand()%10+0;
        *(*(s+i)+j)=x;
    }

}

void xuat(int **s, int line, int column)
{
for(int i=0; i<line; i++)
{
    printf("\n");
    for(int j=0; j<column; j++)
        printf("%3d",s[i][j]);
}
}

int main()
{
int line,column;
printf("\nLine: "); scanf("%d",&line);
printf("\nColumn: "); scanf("%d",&column);

int **s=new int*[line];
for(int i=0; i<line; i++)
    s[i]=new int[column];

nhap(s,line,column);
xuat(s,line,column);

getch();
for(int i=0; i<line; i++)
    delete[] (s+i);
delete[] s;
}

错误:调试断言失败! 表达式:_BLOCK_TYPE_IS_VALID。 有关您的程序如何导致断言失败的信息,请参阅有关断言的 Visual C++ 文档。

【问题讨论】:

  • 在我的电脑上运行良好.. Windows + Visual Studio 10
  • 你不一致,*(*(s+i)+j)s[i][j]。你应该坚持后者,它使用起来更简单。
  • 哦,不。这没有错误。谢谢!

标签: c++ point


【解决方案1】:

delete [] (s+i); 是你的错误。为清楚起见,您可能应该坚持使用常规数组语法。 *(s+i) 的东西是等价的,但更难阅读/理解。所以我会使用delete [] s[i]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 2011-12-08
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多