DEV Community

Owais Athar
Owais Athar

Posted on


Getting Segmentation Fault by Debugger in C.

I'm Getting Segmentation fault by debugger in partition() function at commented variable...following code is a complete implementation of Quick Sort algorithm.

// Sorting Algorithms

void quick_sort(int arr[],int length);
int partition(int a[],int low, int high);
void quick_sort_recursion(int arr[], int low, int high);
void swap(int *x, int *y);

void quick_sort(int arr[],int length){


void quick_sort_recursion(int arr[],int low, int high){

        int pivot_value = partition(arr,low,high);
        quick_sort_recursion(arr,low,pivot_value - 1);

int partition(int arr[], int low, int high){

    int pivot_value = arr[high]; //getting 'segmentation fault' here
    int i = low;

    for (int j = low; j < high; j++)
        if(arr[j] <= pivot_value){

Enter fullscreen mode Exit fullscreen mode

see image here...

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.