Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why and when to use pointers in C?

I’m still very new to C, have only been learning for about a week at this point, but something I don’t get is the use of pointers. I get how pointers work and I know how to use them, but I don’t see why or when they should be used. Can someone please explain this to me?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It is enough to mention that arrays used in expressions with very rare exceptions are implicitly converted to pointers to their first elements.

For example if you will write the expression

arr[i]

where arr is the array name then even in this expression the array is converted implicitly to a pointer to its first element.

Or another simple example: all C string functions deal with pointers of the type char * because passed arrays again are implicitly converted to pointers to their first elements.

Think about how to write a general sort function for arrays of any types.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading