thank you sir, very well explained .

On Sat, Dec 22, 2012 at 12:47 PM, saurabh singh <saurab...@gmail.com> 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 compiler will associate p with an
> address that is *0.*Or in terms of pointers it is  *NULL.* That is
> printf("%d\n",p) should give 0.
> **p=0;*
> *
> *
> What happens when you do **(some_ptr)? *The address stored by some_ptr is
> referred to. So when we try to do **p=0 the address pointed by p is
> referred,which is NULL,and by the law of the land trying to read/write from
> memory with address NULL is sin. *So you get segmentation fault.
>
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
> On Sat, Dec 22, 2012 at 10:52 AM, Saurabh Paliwal <
> saurabh.paliwa...@gmail.com> wrote:
>
>> 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 <jprakha...@gmail.com>wrote:
>>
>>> You are initialising random memory address with 0, which OS doesn't
>>> allow.
>>>
>>> On 12/17/12, Shubham Sandeep <s.shubhamsand...@gmail.com> 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 IT 4th Year
>>> Mob no: +91 9454992196
>>> E-mail: rit2009...@iiita.ac.in
>>>           jprakha...@gmail.com
>>>
>>> --
>>>
>>>
>>>
>>
>>
>> --
>>  -    Saurabh Paliwal
>>
>>        B-Tech. Comp. Science and Engg.
>>
>>        IIT ROORKEE
>>
>> --
>>
>>
>>
>
>  --
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 


Reply via email to