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-26 4:43

You faggots, I can't believe nobody has posted this yet.

#if __STDC_VERSION__ >= 199901L
#  define N sizeof pointer
#else
#  define N 4
#endif

void print_pointer(void *pointer)
{
    static char _[N];
    int i;
    for(i = 0; i < N; i++)
        i[_] = i[(unsigned char *)pointer];
    printf("%.*s\n", (int)N, pointer)
}

Why torture a man who simply asks for help? As if you've never been in the vulnerable position of asking for help!

>>1 This is the best way to print a pointer. Have fun buddy.

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