愿你出走半生,归来仍是少年

^_^

怀揣梦想,永不放弃

导航

strlen() 函数

strlen() 函数通常用来计算字符串的长度,但是今天突然发现个奇怪的现象。

如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char *str;
    int n = 0;
    str = (char *)malloc(30 * sizeof(char));
    printf("%d\n", strlen(str));
    printf("%d\n", sizeof(str));
    return 0;
}

 

 strlen(str) = 34 ?????? 为什么呢? strlen(str) = sizeof(str) + 30 ??? 是吗??

posted on 2015-02-01 01:27  Jeffrey.Downhouse  阅读(563)  评论(0)    收藏  举报

运筹帷幄之中 | 决胜千里之外