Re: Help in c pointers
- From: Kenneth Brody <kenbrody@xxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 10:09:13 -0500
"manochavishal@xxxxxxxxx" wrote:
HI
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
Neither pointer has been initialized, and both assignments invoke UB. In
your particular case, the address in p happened to be invalid for an int,
and the address in msg happened to be valid for a char, and didn't cause
any noticable effect by overwriting that memory.
--
+-------------------------+--------------------+-----------------------------+
| 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@xxxxxxxxx>
.
- Follow-Ups:
- Re: Help in c pointers
- From: Jordan Abel
- Re: Help in c pointers
- References:
- Help in c pointers
- From: manochavishal@xxxxxxxxx
- Help in c pointers
- Prev by Date: Re: stdint.h and portability
- Next by Date: Re: Help in c pointers
- Previous by thread: Re: Help in c pointers
- Next by thread: Re: Help in c pointers
- Index(es):
Relevant Pages
|