動機
不知道為什麼c常出現這種問題,就記錄一下 重點是在c中,所有資料都是數字
想法
- NULL當成數字是0
- ptr是數字(addr)
ptr++
=ptr + sizeof(type of ptr)
code
typedef struct
{
char Name[12];
int Age;
float Weight;
int RollNumber;
} sStudentInfo;
int main() {
sStudentInfo* ptr = NULL;
printf("size: %d\n", (int)(++ptr));
}
Ref
How to find the size of structure in C without using sizeof? Pointer arithmetic in C programming