This is an extended question from
How can i remove this Segmentation fault in C Program
here segmentation fault occur because of stack overflow due to recursion so manny times
so i have changed his code like this..
make a MACRO insted of that function so function call is removed
#include <stdio.h>
static inline void p(char *a, int b);
#define MAGIC(a,b) p(a,b)
void p(char *a, int b)
{
static long int i = 0;
if (i != 350000)
{
printf("\n%ld \t at Hi hello", i);
i++;
return MAGIC(a, b);
} else
{
return;
}
}
int main()
{
char *a = "HI";
int b = 10;
MAGIC(a, b);
printf("\nComplete");
return 0;
}
still i am getting segmentation fault …still stack overflow…. why?
Change
return MAGIC(a, b);togoto START;and add aSTARTlabel in the beginning of the function.Edit:
Example using a
whileloop:Example using a
forloop: