字符串面试题

#include
#include
#include


char * mystrcpy(char * dest, const char * src){
        assert((dest!=NULL) && (src!=NULL));
        char *addr = dest;
        while ((*dest++ = *src++) != '\0')
        ;
        return addr;

}

int main()
{

        int i = 0;
        char str[]="hello,wrold";
        char *p = NULL;
        mystrcpy(str,"H");

        p = str;
        printf ("%x, value:%c.\n", p, *p);
        printf ("%x, value:%c.\n", p+1, *(p+1));
        printf ("%x, value:%c.\n", p+2, *(p+2));

        printf ("str: %s\n", str);
        printf ("str: %c\n", str[3]);

        for(i=0;i<20;i++)
        {
                printf ("%x, value:%c.\n", p+1, *(p+i));
        }
        printf ("sizeof:%d, strlen:%d\n", sizeof(str), strlen(str));

}

[root@allinone01 c]# gcc teststr.c
[root@allinone01 c]# ./a.out
b925b220, value:H.
b925b221, value:.
b925b222, value:l.
str: H
str: l
b925b221, value:H.
b925b221, value:.
b925b221, value:l.
b925b221, value:l.
b925b221, value:o.
b925b221, value:,.
b925b221, value:w.
b925b221, value:r.
b925b221, value:o.
b925b221, value:l.
b925b221, value:d.
b925b221, value:.
b925b221, value:.
b925b221, value:.
b925b221, value:.
b925b221, value:.
b925b221, value: .
b925b221, value:b925b221, value:%.
b925b221, value:sizeof:12, strlen:1
[root@allinone01 c]#

你可能感兴趣的:([,C语言学习,])