Recommendation: Go through the book again and again. This is amongst
the first few examples for pointers.
Help me....
I'm new to the pointers. I can't understand the meaning.
Can anybody tell me the meaning of this code fragment.
float *flp,*flq;
Delcare flp and flq as pointers to a float.
ERROR: flp is used before initializing it, this leads to undefined
results.
If flp is initialized to some value like
| float temp=10.0;
| float *flp,*flq;
| flp=&temp;
flp is the address of temp and *flp is the value stored at that addess
i.e. vlaue of temp.
Therefore, *flp=*flp+10 means dereference flp (get value of temp) add
10 to it and store it at the address stored in flp, address of temp.
Since you are storing a value directly at the some address, which
happens to be that of temp, all the changes you do this way will
reflect when you access the value of temp. SO now if you see the value
of temp it'd be 20. Simple!
Dereference flp, get value 20, and increment it.
Derefernce flp and increment it.
copy value in flp to flq. so that *flp is same as *flq.
This example AFAIT is for showing that post/preincrement operators'
precendece is higher than that of dereferncing operator and that post
increment/decrement happens before dereferncing. Pre is anywayz
obvious.
| float *flp,*flq,temp=10.0;
| flp=&temp;
| *flp=*flp+10;
| ++*flp;
| (*flp)++; /* different from *flp++, try this and see for yourself*/
| flq=flp;
| printf("%f\n%f",*flp,*flq);
You can also print the values of flp and flq to verify that they are
same.
flp temp 0x0008 (Address)
________ address of temp ________
|0x0008 | ---------------->| 10 |
-------- *flp --------
Hope this poor piece of art makes some sense when I post it!
HTH
Regards,
Taran