Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-22 Thread Shubham Sandeep
thank you sir, very well explained . On Sat, Dec 22, 2012 at 12:47 PM, saurabh singh wrote: > **p; * > Explanation: By default C thinks everything is an int. So p is a global > variable of type *pointer to an int.*Now like other global variables it > is very very very very likely that the compi

Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread saurabh singh
**p; * Explanation: By default C thinks everything is an int. So p is a global variable of type *pointer to an int.*Now like other global variables it is very very very very likely that the compiler will associate p with an address that is *0.*Or in terms of pointers it is *NULL.* That is printf(

Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread Saurabh Paliwal
I am afraid both of you are incorrect.. 1. since the code modified by you will compile but give sigsegv anyway. 2. The statement " *p = 0; " has nothing to do with the " random address" you are talking about. On Mon, Dec 17, 2012 at 7:25 PM, Prakhar Jain wrote: > You are initialising random memo

Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread Anjali Sharma
compiler fails to know the type of memory to be pointed to (int, char...etc.) by p... thus leading to a runtime error ! the modified code compiles : int *p;main(){*p=0;} On Mon, Dec 17, 2012 at 8:51 PM, Saurabh Paliwal < saurabh.paliwa...@gmail.com> wrote: > because p is a dangling pointer and

Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread Prakhar Jain
You are initialising random memory address with 0, which OS doesn't allow. On 12/17/12, Shubham Sandeep wrote: > how does this code achieve SIGSEGV > code: > *p;main(){*p=0;} > > -- > Regards, > SHUBHAM SANDEEP > IT 3rd yr. > NIT ALD. > > -- > > > -- -- Prakhar Jain IIIT Allahabad B.Tech

Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-17 Thread Saurabh Paliwal
because p is a dangling pointer and that you can't modify what it's pointing to. On Mon, Dec 17, 2012 at 7:10 PM, Shubham Sandeep wrote: > how does this code achieve SIGSEGV > code: > *p;main(){*p=0;} > > -- > Regards, > SHUBHAM SANDEEP > IT 3rd yr. > NIT ALD. > > -- > > > -- -Sau

[algogeeks] how does this code achieve SIGSEGV

2012-12-17 Thread Shubham Sandeep
how does this code achieve SIGSEGV code: *p;main(){*p=0;} -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --