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: L. A. Calculus 2013-06-26 5:37

>>25
void print_pointer(const void *ptr)
{
    size_t i;

    fputs("0x", stdout);
    for (i = 0; i < sizeof ptr; i++)
        printf("%02x", ((unsigned char *) &ptr)[i]);
    puts("");
}


WHETHER DIS IS GOOD OR NOT DEPENDS ON DA FUCKING C IMPLEMENTATION. ALL DIS DOES IS PRINT OUT DA INTERNAL REPRESENTATION OF DA POINTER IN SEX YA DECIMAL. DAT CUD REPRESENT A NULL POINTER AS A NAKED DONKEY FOR ALL THE STANDARD CARES.

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