&integer_name seems so useless...

Jul 2, 2013 at 11:11am
I am reading a c++ book and in everything i have read until yesterday was understantable and evererytime i said, yes i can use this to do this

But today i read 10 pages of this whole thing about bytes for example:

1
2
3
4
5
6
int n=44;
//which means &n = 0x0064fddc 

//and then it is this
int* pn=&n;
//which means *p=44; 


Just why should i learn something like this?
Last edited on Jul 2, 2013 at 11:12am
Jul 2, 2013 at 11:30am
1) Dynamic memory management

2) To get around the fact that C++ uses pass-by-value (although you can also use references for this)

3) Pointer arithmetic (although this is less of an issue in C++, as STL containers and iterators make life easier)

4) Polymorphism (although, again, you can use references)

5) Because at some point, you'll almost certainly find yourself using a 3rd-party library whose API uses them.

6) Using it as an incomplete type to avoid circular dependencies (from Peter87)
Last edited on Jul 2, 2013 at 12:58pm
Jul 2, 2013 at 11:48am
Implement a linked list and you will understand why you need pointers.
Jul 2, 2013 at 12:57pm
Implement a linked list and you will understand why you need pointers.


Good point. The need to use incomplete types to resolve circular dependencies should have been no. 6 on my list! In fact, I'll edit it in.
Topic archived. No new replies allowed.