General Protection Fault

General Protection Fault


#include #include void main(){  randomize();        const int max_num=1000;        int value[max_num]={0};        const num_word_per_line=8;        cout<<"The random values before sorting:  
";  //assign therandom toan array        for (int i=0;i

This is a very simple, random numbers generation program. However, I get "General Protection Fault" every time I try to run it. When I change const int max_num=1000; to const int max_num=800;, it works. However, it wouldn't work when max_num is over 800. Can you tell me what causes this error and how can I fix this problem? I'm using Borland C++ 4.5, Windows 95, P200 MMX with 32MB RAM.

It would probably be helpful if you could have stepped through your program and determined which line causes the error. A general protection fault is actually enforced by the processor and reported by the operating system. All it really tells you is that one of the many rules set up by the operating system was violated.

So it's hard to get specific here, but I did notice that you are declaring your value array locally in your function. This means the data is allocated locally on the stack and it may be that you are simply running out of stack space. An easy fix would be to be to simply prepend the static keyword to your declaration.

static int value[max_num]={0};
This causes the variable to be allocated from your program's heap instead of the stack. If this doesn't fix the problem, then you'd need to dig a little deeper. Stepping through the program would probably be the next step.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes