Re: Help in c pointers
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 28 Feb 2006 10:20:41 -0500
"manochavishal@xxxxxxxxx" 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/>
.
- Follow-Ups:
- Re: Help in c pointers
- From: Kenneth Brody
- Re: Help in c pointers
- References:
- Help in c pointers
- From: manochavishal@xxxxxxxxx
- Help in c pointers
- Prev by Date: Re: Help in c pointers
- Next by Date: Printing Patterns using for loops
- Previous by thread: Re: Help in c pointers
- Next by thread: Re: Help in c pointers
- Index(es):
Relevant Pages
|