Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
stop68702y1. 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. -
@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
-
@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!
-
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! -
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.
Related Rants
-
PaperTrail7Worst fight I've had with a co-worker? Had my share of 'disagreements', but one that seemed like it could hav...
-
bashleigh16I lost my job 😅 tbh did me a favour. I was backend, this guy was frontend and was a typical opinionated Jav...
-
johnmelodyme15There's this guy who randomly make sexual remarks. Not the usual guy's talk kind sexual remarks, but more of "...
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());
}
question
wk318