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

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

    Just another exception to the already posted list. On 32-bit platforms, pointers can take 6, not 4, bytes:

    #include 
    #include 
    
    int main() {
        char far* ptr; // note that this is a far pointer
        printf( "%d\n", sizeof( ptr));
        return EXIT_SUCCESS;
    }
    

    If you compile this program with Open Watcom and run it, you'll get 6, because far pointers that it supports consist of 32-bit offset and 16-bit segment values

提交回复
热议问题