On Mon, 01 Aug 2005 23:07:14 -0400, "maadhuu"
There is no such thing as a "pointer to null". There is a null
pointer, and there can be null pointers of any pointer type. A null
pointer does not point to address 0, and it does not point to "null",
in fact it is specifically defined NOT to point to anything that your
program has the right to access.
hello ,
i want to know the behaviour of the pointer under the following
condition.
the code snippet is as follows :
#include<stdio.h>
int main()
{
int *p = 0;
++p;
The line above attempts to perform pointer arithmetic on a null
pointer. This is not allowed by the C standard and has undefined
behavior. So from here on, C does not know or care what happens.
Oops, more undefined behavior here. The "%d" conversion specifier for
printf() requires an argument of type int, not any kind of pointer.
If you want to print the value of a valid pointer, which yours is not
after you try to increment it, you need to cast it to a pointer to
void and use the "%p" conversion specifier:
printf("%p\n", (void *)p);
Notice that I also added a '\n' on the printf() statement. If the
last line sent to stdout does not end in a '\n', the C standard does
not require it to ever appear, and on some platforms it does not.
return 0;
}
what will be the output ???? is is always the same ???? say, size of
integer on this machine is 4.
The output will be whatever it is if you compile and run the program,
assuming it outputs anything at all. The behavior of the increment is
undefined, just like division by 0 in mathematics. As far as the C
language is concerned, anything at all that happens is just as right
or wrong as anything else.