0强转为指针的用处

xiaoxiao2021-02-28  126

   ANSI C 标准允许任何值为0的常量被强制转换为任何类型的NULL指针 

    因此(type*)0  是一个类型为type类型的一个空指针  但是它不能被赋值  只能被用作本类型的地址来使用

   eg:  struct student

                 {

                    int id;

                    char name[20];

                 };

          ((struct student*)0)->id=2;   这样是不对的  它主要用于当结构体实例的首地址为&((struct student*)0)时  id字段的地址&((struct student*)0)->id

          既偏移地址

转载请注明原文地址: https://www.6miu.com/read-22501.html

最新回复(0)