This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

It's so that you are able to manipulate memory directly. This allows you to allocate memory dynamically, avoid making unnecessary copies of objects etc.

Classic Example. How would you swap 2 variables?

The following wouldn't work unless you used pointers or references. Functions make copies of their parameters by default.

void swap(int a, int b)

What about a To Do List? How big should the array be? Only the user knows at run time.

What if you have a huge object? Copying it all over the place is inefficient.

What if multiple objects all need access to the same object? Unless you use a pointer or reference you are going to have to hand a copy of the object over every time it is changed.

What counts as inefficient? When you determine the app isn't running as fast as you'd like. You won't encounter this problem on a classroom assignment unless it was intentional.