-3

Why this code is not give any output?
When i run,it gives me ERROR like SEGMENTATION FAULT CORE.
(C language)

#include <stdio.h>
void fun()
{
int arr[5] = {1, 2, 3, 4, 5};
int i, j;
static int n = -1, b = 0,k = 1;
int mari[5];
int max = arr[0];
if (k > 5)
return ;
for (i = 0; i < 5; i++)
{
if (arr[i] >= max)
{
for (; b <= 0; b--)
{
if (mari[b] == i)
{
continue;
}
max = arr[i];
n = i;
}
}
}
mari[b] = n;
b++;
k++;
printf("sdg %d", max);
fun();
}
void main()
{
printf("%d", fun());
}

Comments
  • 7
    This isn't SO . don't put this garbage Code on here
  • 8
    1. We don't do homework
    2. Clean up the code
    3. Run the code in your mind
    It helps to have an editor open with the variables and the values they have at the line you are looking.
    4. The wkXXX are for rants that have an theme.
  • 1
    Sorry I don't know what a SEGMENTATION FAULT CORE is
  • 4
    @gugrfchijvf https://en.wikipedia.org/wiki/... and now put in some work yourself and don't just ask other people to fucking fix it for you. Man this makes me mad
  • 0
  • 1
    @gugrfchijvf It's alright, just please read the compiler and OS outputs (segmentation fault in this case) and actually try to understand what it says. Also make sure to check your compile warnings. Your goal should be no warnings at all. Also Google is a programmers best friend!
  • 0
    @12bitfloat sure thank you
  • 1
    Well since you're not using malloc, I'm guessing it's a stack overflow. Check the terminating case in your recursion.

    Edit again: and missed an obvious one. You're trying to output the returned value from a void function!
  • 0
    @d4ng3r0u5 is there any option to stop stack overflow or increase a size of it?
  • 0
    @gugrfchijvf I don't know how about you fucking google it
  • 1
    Aha. I think in your inner loop you may access mari[b] while b is negative. Out-of-bounds array or pointer use can absolutely cause a segfault.
Add Comment