-1

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?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
joshjkk
  • 25
  • 1
  • 4
  • How would you write a function to operate on any collection of data (be it list, array, whatever else) without pointers in C? – PeterT Jun 05 '22 at 16:36
  • Does this answer your question? [Why Use Pointers in C?](https://stackoverflow.com/questions/29423757/why-use-pointers-in-c) – RAZ0229 Jun 05 '22 at 16:40
  • 1
    There is also [Why use pointers?](https://stackoverflow.com/q/162941/2505965), but many of the answers are problematic. – Oka Jun 05 '22 at 16:43
  • Yes, I understand the use of pointers a lot more now, sorry for asking such a newbie question, thank you all! – joshjkk Jun 05 '22 at 16:46
  • [What are the barriers to understanding pointers and what can be done to overcome them?](https://stackoverflow.com/q/5727/995714), [Why use pointers?](https://stackoverflow.com/q/162941/995714) – phuclv Jun 05 '22 at 16:48
  • You would use pointers when you are in a situation where pointers are useful. When you are wondering how to solve something, and then you realize you can use a pointer. – user253751 Jun 06 '22 at 00:05

1 Answers1

-1

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335