PDA

View Full Version : اشارگر null



نغمه
دوشنبه 03 خرداد 1389, 14:53 عصر
اگر بخوام یک اشاره گر به هیچ جا اشاده نکنه به عبارتی نول باشه باید صفر در اشاره گر بریزم؟ اصلا صفر جزو آدرس های معتبر هست یانه ؟ میشه از آدرس صفر استفاده کرد؟

Nima_NF
دوشنبه 03 خرداد 1389, 17:11 عصر
بهتر هست NULL جلوی آن قرار دهید. 0 هم می توانید قرار دهید.



int*pr = NULL;



این هم گفته خود Stroustrup هست، بد نیست مطالعه کنید:



Should I use NULL or 0?
In C++‎, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days. If you have to name the null pointer, call it nullptr; that's what it's going to be called in C++‎0x. Then, "nullptr" will be a keyword.