For Programmers: Free Programming Magazines  


Home > Archive > C > February 2006 > Re: Help in c pointers









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Help in c pointers
CBFalconer

2006-02-28, 6:55 pm

"manochavishal@gmail.com" wrote:
>
> int *p;
> *p = 4;
>
> char * msg;
> *msg = 'c';
>
> printf("msg is %s",msg);
>
> when i try to pass a value 4 to place what integer pointer p
> points to it says seg fault but for the char pointer it works fine.
>
> Why this behaviour


You were unlucky with the char pointer.

Neither p nor msg points anywhere. Trying to dereference either of
them results in undefined behavior. Undefined behaviour includes
"working". It also includes launching flying pigs.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


Kenneth Brody

2006-02-28, 6:56 pm

CBFalconer wrote:
[...]
> Neither p nor msg points anywhere. Trying to dereference either of
> them results in undefined behavior. Undefined behaviour includes
> "working". It also includes launching flying pigs.


Can demons come out of a flying pig's nose?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com