c++ - Are these null pointers, or are they pointers to address 0? -


if write

int 0 = 0;  void *p1 = (void *)0; void *p2 = (void *)(int)0; void *p3 = (void *)(0 /*no-op, affect next zero?*/, 0);  void *p4 = (void *)zero;    // reference, pointer address 0 void *p5 = 0;               // reference, null pointer void *p6 = null;            // reference, null pointer void *p7 = nullptr;         // reference, null pointer (c++11)  static const int static_zero_1 = 0;       // literal 0 when used? static const int static_zero_2 = 1 - 1;   // no "literals 0" per se... it? void *p8 = (void *)static_zero_1;   // have seen weird substitution rules... void *p9 = (void *)static_zero_2;   // apply null too? 

which of p1, p2, , p3 (edit: added p8 , p9) null pointers (i.e. == null, may or may not address zero), , of them pointers address 0 (may or may not == null)?

if answer different in c , c++, in each of them?

p1 , p2 null pointers; p3 implementation defined, , may else. (a comma operator cannot part of constant expression. , mapping of non-constant integral value 0 pointer implementation defined.) c identical c++ here.

p8 , p9 both null pointers in c++, not in c.

with regards comment on static_zero_2, there no requirement in either language literal 0 present, anywhere. g++ defines null compiler built-in __null, example, , can use (1 - 1), or '\0', or other constant expression evaluating 0.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -