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

前端 未结 17 1331
温柔的废话
温柔的废话 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:42

    The guarantee you get is that sizeof(char) == 1. There are no other guarantees, including no guarantee that sizeof(int *) == sizeof(double *).

    In practice, pointers will be size 2 on a 16-bit system (if you can find one), 4 on a 32-bit system, and 8 on a 64-bit system, but there's nothing to be gained in relying on a given size.

提交回复
热议问题