首页 > 解决方案 > sizeof-operator 反向行为

问题描述

我们知道,当我们使用数组时,它保存第一个元素的地址,&array 存储整个数组地址,当我在 printf 中使用它时它是正确的,但在 sizeof 运算符中它是相反的行为,为什么

我在 Windows 7 上使用带有 GCC 的代码块

 int main(void)
  {
    int c[5];
      printf(" %d  %d  %d  %d\n",c,c+1,&c,&c+1);\\when we add 1 in "c" it add more 4 bytes and when "&c+1" it add 20 byte witch is true

       printf(" %u  %u ",sizeof(c),sizeof(&c));\\But when we print first element size (with "c") it give 20 byte and when print (With "&c") whole arry size it give 4 byte


         return 0;
            }

\我不明白为什么请解释

标签: csizeof

解决方案



推荐阅读