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
Keith Thompson

2006-02-28, 7:55 am

"manochavishal@gmail.com" <manochavishal@gmail.com> writes:
> int *p;
> *p = 4;


p is uninitialized. Attempting to dereference it invokes undefined
behavior.

> char * msg;
> *msg = 'c';


msg is uninitialized. Attempting to dereference it invokes undefined
behavior.

> 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.


Both are possible consequences of undefined behavior.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sponsored Links







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

Copyright 2009 codecomments.com