Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pointers in C

Name: Anonymous 2013-06-25 17:59

Hey guys I'm having a little trouble with the following example

#include <stdio.h>
int main(void)
{
char s[] = "Melbourne City";
printf("%s\n", &s[2]);
return 0;
}

which prints "lbourne City" instead of the address of letter 'l'.
I do understand that the %s in the printf continues until a null terminator is hit, but not why &s[2] returns a character in the first place.
Thanks.

Name: Anonymous 2013-06-27 13:27

Soooo... if we assume an ILP32 system, what is inherently wrong about

printf("%u", &a);

given that it just works fine, and you know it will give decimal output? Why bother with

printf("%u", (int)&a);

if it does not really make a difference, or

printf("%p", (void *)&a);

which may or may not give decimal output (and tends to mostly give hex output)?

Calculus Guy 'RETOID' type rants welcome.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List