刷题学习中遇到的各种问题

这里po一下在学习过程中遇到的各路奇(hua)葩(ji)问题

段错误(SEGFAULT)
官方的解释是这样的

A segmentation fault (often shortened to segfault) is a particular error condition that can occur during the operation of computer software. In short, a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Systems based on processors like the Motorola 68000 tend to refer to these events as Address or Bus errors.
Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, “segmentation fault” being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy.
On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal. On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception.

一句话来说,段错误就是指访问的内存超过了系统预定分配给其的内存空间。列如:野指针

这里放一下我出错的代码

#include 
#define MAXL 10010
#define MAXH 110
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    long long array[MAXH][MAXL];
    for(int i=0;i>array[i][j];
    long long max=-100;
    int no=0;
    for(int i=0;imax)
        {
            no=i;
            max=array[i][0];
        }
    }
    cout<

这里编译器报错

Signal=SIGSEGV(Segmentation fault)
n={int}
m={int}
max={long long}

但是我并没用用指针啊,emmm我找了一个小时也不知道在哪儿…第二天突然想起来可能是这个array数组的问题,我把它放在main()的外面就好了.不知道是什么原因.不过以后还是记着点儿数组定义放在外面.

你可能感兴趣的:(acm,段错误)