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

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...