Saturday, September 16, 2017

Understanding POINTERS in C



Pointers is a very easy concept, the confusion arises because the declaration and de-referencing  look very similar

you declare a pointer as        :   int * p     // DECLARING p as a pointer to  a data of type int 
you de-refernce it  as             :         *p    // Is a VALUE , achieved by DE-referncing the pointer p ( ' Data type' int not )
you use it as                           :          p    // the * is absent when you use it   ( * is not written when actually using pointer)

They appear to be same, only the 'int' ie data type is absent in the second case. So , when ever a * operator is preceded by a data type like int, char , struct etc its a DECLARTION , else its a VALUE ( ie got by de-referencing the pointer).
And further confusion is added, because when you use the pointer, it does not have the * operator before it , so the pointer is only 'p',


Thanks
Ashutosh

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...