segmentation fault

int main()
{
int i=8;
int *p=&i;
printf("%d",*p);
*++p=2;
printf("%d",i);
printf("%d",*p);
printf("%d",*(&i+1));
return 0;
}

guess what is the output and will it depends on underlying operating system we are using.

Comments

  1. when we are incrementing p, it is pointing to an invalid location, so i guess it should generate a segmentation fault in linux systems....i am not sure about windows in this case...kindly explain.

    ReplyDelete
  2. yeah you are right but this is irrespective of operating system.If you are using same compiler with right flag set then it will work in the same way.

    ReplyDelete

Post a Comment

Popular posts from this blog