美文网首页
C语言知识

C语言知识

作者: YH的练手记 | 来源:发表于2016-11-12 00:00 被阅读7次

    1.指针

    int main(){

    char str2[10]="Hello";

    printf("sizeof(str2): %d bytes\n", sizeof(str2));//  10     == array.length

    printf("sizeof(&str2): %d bytes\n", sizeof(&str2));//sizeof(char*)

    printf("%p\n", str2); // 0x7fff5fbff79e  

    printf("%p\n", str2 + 1); //0x7fff5fbff79f  (== 0x7fff5fbff79e + 1)

    printf("%p\n", (&str2));// 0x7fff5fbff79e

    printf("%p\n", (&str2 + 1));0x7fff5fbff7a8 (== 0x7fff5fbff79e + 10 (== array.length))

    printf("\n%p %c, %p %c\n",str2, *(str2), *(&str2), **(&str2));

    // 0x7fff5fbff79e H, 0x7fff5fbff79e H      

    // str2 == *(&str2) , *(str2) == **(&str2)

    return 0;

    }

    http://stackoverflow.com/questions/15177420/what-does-sizeofarray-return/15177499#15177499   

    其中答案还具体解释了Difference between char *str and char str[] and how both are stored in memory。

    相关文章

      网友评论

          本文标题:C语言知识

          本文链接:https://www.haomeiwen.com/subject/itzfpttx.html