What is the output and does it depend on underlying operating system we are using.
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;
}
Useful Links:
http://en.wikipedia.org/wiki/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;
}
Useful Links:
http://en.wikipedia.org/wiki/Segmentation_fault
When we are incrementing p, it is pointing to an invalid location,so it should generate a segmentation fault.
ReplyDeleteThis is irrespective of operating system.If you are using same compiler with right flag set then it will work in the same way.