Hello ladies and gents,
Ive been reading about pointers abit and at there are two pieces of text in the book about pointers wich aren't clear to me, was wondering if any of you could enlighten me abit about them! :D
Sometimes it's desired to clearly point out that a certain pointer doesn't point to anything. We can give that pointer a value of 0. To declare this value, we have to write it either with 0 or as most of the times NULL. THis is however not a determinated word, but a constant wich in many headers, like iostream is defined like that. Another value for a pointer then 0 is not possible.
double *p; p = 0; // valid p = NULL; // valid p = 123; // not valid
1) QUESTION IS: how can a pointer be NULL or 0 when it's an adress wich gives a value?
Because, as I understand it to be like this:
Expression----------------Type--------------Value
p-------------------------pointer-to-double--an adress
*p------------------------double-------------(12.34)
Or, is it saying that when declaring p = NULL;, the adress of that pointer is 0x00000000 and there is no value stacked in this pointer?
Also, when do you use this?
2) Can someone explain what the use is of typedef and how I can interpret this explanation?
When this is declared: typedef char *pointer
the pointer becomes an indication of the type char*. This means that the following two declarations are equivalent:
char *p;
pointer p;
Ive found this on the net:
The following example provides the type DRAWF for a function returning no value and taking two int arguments:
typedef void DRAWF( int, int );
After the above typedef statement, the declaration
DRAWF box;
would be equivalent to the declaration
void box( int, int );
Wich I understand, it's saying that the parameters from the function DRAWF are also the parameters for box. That I understand!
Don't understand however what's happening with the example with pointers?
Any additional info is greatly appreciated as usual ;)