Segmentation fault occurs when you try to access a memory which doesn't
belong to your program.

You are trying to cast a memory location of one byte to 4 byte(assuming
size of long int to be 4). It is possible that other three bytes belong to
some other process.
That is why you are getting segmentation error.

Correct me if m wrong.



* *

**
*
*



On Wed, Jul 18, 2012 at 4:55 PM, vindhya chhabra
<vindhyachha...@gmail.com>wrote:

> is it due to accessing the long at odd address?
>
> On Wed, Jul 18, 2012 at 4:54 PM, vindhya chhabra
> <vindhyachha...@gmail.com> wrote:
> > #include < stdlib.h>
> > #include < stdio.h>
> > int main(void)
> > {
> > char *c;
> > long int *i;
> > c = (char *) malloc(sizeof(char));
> > c++;
> > i = (long int *)c;
> > printf("%ld", *i);
> > return 0;
> > }
> > please explain how bus error occurs  here..i am not clear about bus
> > error and segmentation fault..plz help.
> >
> >
> > --
> > Vindhya Chhabra
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> Vindhya Chhabra
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to