vire said:
so you get a constant 0 if you use NULL. right?
That depends on the expansion of NULL. So long as it expands to a
null pointer constant, that's OK. 0 is a null pointer constant,
but there are null pointer constants that are not (literally) 0.
then in
int *p=NULL;
p is a null pointer
and
int *p=(int*)0x13ff7c;
p is point to address 0x0013ff7c;
No, `int *p=(int*)0x13ff7c;` is either undefined or implementation-defined
(I forget which, but it doesn't matter here). How an implementation
chooses to convert an integer to a pointer isn't specified by C. It's
expected to be useful (or at least not deliberately useless) on your
platform, but that's not part of the definition, that's part of not being
a stupid implementation - not all uses of C need be portable.
i think the null pointer is indeed point to some place(the address
0).but we just call it null.
You can think that if you like, but that doesn't make it true. All that's
required is that assigning a null pointer constant to a pointer gives that
pointer a value that doesn't compare equal to the address of any (C) object.
In particular, there is /no requirement/ that the null pointer /value/ be
some all-bits-zero value. A sufficiently determined implementor could
represent it with the bit-pattern 0x11, or 0x2a, or 0xdeadbeef. And
whatever bit-pattern gets chosen, it can be arranged that there is nothing
at that address, with the co-operation of the operating system.
Using all-bits-zero is frequently possible and convenient and used; but it's
not /required/.
and we can not read or write on address 0.is that right?
C doesn't say. It doesn't say /anything/ about "address 0". If an implementation
has an "address 0", it may (or may not) allow you to read it, and it may (or
may not) allow you to write to it.
what i want to say is , the value of p is 0
so i think a pointer point to address 0 is so called null pointer ,is
that right?
The value of `p` is the null pointer.
int a;
int* p=&a;
p+1;
is p+1 defined by c language ?
Yes. It is legal to point one past the end of an object. (Otherwise a whole
slew of looping idioms would be illegal.)
plz tell me.i really don't have any idea about it.
Books. And the standard.