Pointers

Aug 21, 2013 at 9:42pm
I have recently read about pointers but I have not yet discovered why I should use pointers instead of just normal ints or chars and so on.
Why should I even use pointers at all?
Aug 21, 2013 at 9:50pm
Because
1) you might need to keep track of the address of something.
2) some library calls expect pointers.
3) you might want to allocate something on the heap. new returns a pointer.
Aug 21, 2013 at 9:59pm
Consider for example designes of linked lists or processing of character arrays. For example consider standard C function strchr

Its declaration (in C) is

char * strchr(const char *s, int c);

Last edited on Aug 21, 2013 at 10:00pm
Aug 21, 2013 at 11:17pm
See my post in this thread:

http://cplusplus.com/forum/general/105593/

for some reasons to use pointers.
Aug 22, 2013 at 10:59am
Okay, that makes sense. Thank you all!
Topic archived. No new replies allowed.