segmentation fault

sometimes for this code i get a segmentation fault for codes llike this

:

int main{
int * a= 0;
int b;
a = (int*)malloc(sizeof(int));
///some code using these variable but no freeing of a

 if\(a\)\{
       free\(a\);
       a = 0;
 \}
 return 0;

}

The problem is probably in the code you did not post. But I will mention that malloc will fail if the data segment has maxed out. I don't see you test for that. You'll get a null pointer with errno set to ENOMEM. Dereferencing a null pointer can cause a seg fault on some architectures.

thanks buddy your a gr8 help but will trouble you later for more queries :smiley: .for now have this one.which is the command which asks the system to wait for some time(say millisec)before printing some statement
eg
something like this
waiting . . . . .

code is
int i;
for(i =0;i < 10;i++){
printf(" .");
//command i'm loooking which waits for(say 300 ms) (works in linux not windows)
}
printf("\n");

plz reply thanx

See: nodoff sleep for less than a second