Share this article
Improve this guide
What is Segmentation Fault: 11 & How to Fix it
Seg fault 11 can be easily avoided by assigning values to your global variables
3 min. read
Updated onOctober 4, 2023
updated onOctober 4, 2023
Share this article
Improve this guide
Read our disclosure page to find out how can you help Windows Report sustain the editorial teamRead more
Key notes
C is one of the most used programming languages. But sometimes, while developing new software, you might encounter an error: Segmentation fault : 11.
Thiserrorwill cause your application to crash, and in today’s article, we’re going to show you what thiserrormeans and how to fix it once and for all.
Obviously, you’ll need a bit more context in order to fully grasp the meaning of code 11 segmentation fault: 11. Understanding the triggers will prove useful in selecting the right debugging tools.
So, what causes a segmentation fault 11? Let’s take a closer look at the various run-time instances that are likely to display this error and also review its potential causes:
What is segmentation fault 11?
When Segmentation fault: 11 occurs, it means that a program has attempted to access amemorylocation that it’s not allowed to access.
Theerrorcan also occur if the application tries to accessmemoryin a method that isn’t allowed. This usually concerns strings and allocating the right amount of memory for particular string types in C.
Under issue that can trigger a Segmentation fault: 11 error is the lack of values attributed to the global variables in your code. And speaking of variables, using an incorrect format character can have the same effect.
How can I fix Segmentation fault: 11?
Before we dig, make sure you check these prerequisites:
➡️ List the variables and functions in the header and make them accessible via # (You can alsouse pro software to learn C++and take advantage of the tips and tricks that come along with it.)
➡️ Separate your code into different files for easier debugging (Just like regulardebugging tools for Windows,lldbandgdbwill work better on a defined perimeter with defined constants.)
1. Compile the code and use gdb
$ gdb ./a.out
(gdb) run
(gdb) backtrace
In addition, users also recommend running these twocommands:
lldb executable_name
run -flag1 -flag2
While we’re at it, you might also want to take a look at theseexcellent C++ compilers for Windowsthat are free of charge.
2. Inspect your code
This is also a useful tip if you’re getting Segmentation fault: 11 while using Python.
3. Use the malloccommand
free()
4. Use the char var/int arrcommand
In your code, use the followingcommand:
char var[strlen(x)+1]
int arr[(sizeof(x)/sizeof(x[0]) +1)]
Use one of thesecommandsdepending on your needs.
? Segmentation fault 11 Python
On your Mac, run the followingcommand:
pip uninstall shapely; pip install –no-binary :all: shapely
Keep in mind that this method might only work if you’re trying to install Cartopy.
cd /Library/Frameworks/Python.framework/Versions/3.3
cd ./lib/python3.3/lib-dynload
sudo mv readline.so readline.so.disabled
Segmentation fault 11 is usually caused bymemoryallocation issues, and if you’re having this problem, be sure to try some of the solutions mentioned above.
More about the topics:Programming tools and tips
Milan Stanojevic
Windows Toubleshooting Expert
Milan has been enthusiastic about technology ever since his childhood days, and this led him to take interest in all PC-related technologies. He’s a PC enthusiast and he spends most of his time learning about computers and technology.
Before joining WindowsReport, he worked as a front-end web developer. Now, he’s one of the Troubleshooting experts in our worldwide team, specializing in Windows errors & software issues.
User forum
0 messages
Sort by:LatestOldestMost Votes
Comment*
Name*
Email*
Commenting as.Not you?
Save information for future comments
Comment
Δ
Milan Stanojevic
Windows Toubleshooting Expert
Before joining WindowsReport, he worked as a front-end web developer. Now, he’s specialized in Windows errors & software issues.