Puzzling program
- From: Rajeet Dalawal <rd@xxxxxxxxxxxxxx>
- Date: Thu, 9 Aug 2007 00:31:14 +0200 (CEST)
Good day group.
I was asked in an interview to explain the behavior of this program.
void main()
{
char *s = "abc";
int *i = (int *) s;
printf("%x", *i);
}
The question is: why is the output 636261? I don't think I know enough
about C to understand how the conversions between pointer types are
occurring.
Thanks for any help.
RD
.
- Follow-Ups:
- Re: Puzzling program
- From: Kenneth Brody
- Re: Puzzling program
- From: Jalapeno
- Re: Puzzling program
- From: stdazi@xxxxxxxxx
- Re: Puzzling program
- From: Richard Heathfield
- Re: Puzzling program
- From: Martin Ambuhl
- Re: Puzzling program
- From: Joe Wright
- Re: Puzzling program
- From: Malcolm McLean
- Re: Puzzling program
- From: Lew Pitcher
- Re: Puzzling program
- From: Walter Roberson
- Re: Puzzling program
- Prev by Date: Re: Improvements in a loop : ++i better than i++ ?
- Next by Date: Re: Improvements in a loop : ++i better than i++ ?
- Previous by thread: Re: Preserving the value of errno
- Next by thread: Re: Puzzling program
- Index(es):
Relevant Pages
|