Is the sizeof(some pointer) always equal to four?

前端 未结 17 1405
温柔的废话
温柔的废话 2020-11-22 11:49

For example: sizeof(char*) returns 4. As does int*, long long*, everything that I\'ve tried. Are there any exceptions to this?

17条回答
  •  忘掉有多难
    2020-11-22 12:43

    In addition to the 16/32/64 bit differences even odder things can occur.

    There have been machines where sizeof(int *) will be one value, probably 4 but where sizeof(char *) is larger. Machines that naturally address words instead of bytes have to "augment" character pointers to specify what portion of the word you really want in order to properly implement the C/C++ standard.

    This is now very unusual as hardware designers have learned the value of byte addressability.

提交回复
热议问题