sizeof behaving unexpectedly

前端 未结 4 1058
再見小時候
再見小時候 2021-01-04 09:02

Consider the following code:

  #include 
  int main(void)
  {
    int a[10];
    printf(\"%d\",(int)sizeof(a)); //prints 10*sizeof(int) (40 on         


        
4条回答
  •  感动是毒
    2021-01-04 09:30

    (a-3) has type int*, and it prints you sizeof(int*) which is 4 on your platform.

    And note that sizeof() is no longer compile-time constant in C99 (due to variadic-length arrays).

提交回复
热议问题