From: Nitin Dubey [mailto:[EMAIL PROTECTED] 
>On Fri, 24 Dec 2004 07:51:02 -0800 (PST), Angsumankar Kar
><[EMAIL PROTECTED]> wrote:
>> Please explain it:
>>  
>> void main()

main returns int, not float, class foo or void.

>>  {
>>    int *p=258;

Here you declare a pointer, and initialise it to point to a piece of
memory described as '258'

This is likely to invoke (as you in fact do on the next line) undefined
behaviour. i.e. anything is possible. Perhaps you meant something like:

    int q = 258;
    int *p = &q

>>    printf("%d %d",*(char *)p,*(char *)p++);

Here you try to read and write whatever happens to be at address '258' -
the fact you're attempting to do both between two sequence points again
invokes undefined behaviour. This is like the expression  i = i++; - it
makes no sense in the context of C or C++.

>> }
>>  
>> output:0,2

Any output is permitted for reasons explained above...

>i tried running this code on my pc but its giving segmentation
>fault........

.. and as someone else has tried, other possibilities are allowed.

>if its running on your system then compile it with
>printf("%d %d %d %d",*(char *)p,*(char *)p++, *(char*)p++, 
>*(char*)p++);

This is also broken code (undefined behaviour - see comment about i =
i++; above)

>if it gives you output 0 2 1 0 then i think i know why its giving you
>this output.....
>please just check it out.

--
PJH
"The difference between genius and stupidity is that genius had its
limits." 
    - Albert Einstein



Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12 
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272

Website : www.alderley.com  Sales : [EMAIL PROTECTED] Service : [EMAIL 
PROTECTED]

This email and its contents are confidential and are solely for the use of the 
intended recipient. If you are not the original recipient you have received it 
in error and any use, dissemination, forwarding, printing or copying of this 
email is strictly prohibited. Should you receive this email in error please 
immediately notify [EMAIL PROTECTED]

This email has been scanned for viruses, however you should always scan emails 
with your own systems prior to opening.









------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4907
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to