What are pointers used for in real life?
Time for a noob question. I know what pointers are and how they are used. But I'm still struggling with when I'm supposed to use pointers instead of "regular" variables. E.g. almost every tutorial teaches you how to use pointers by using them for really basic things like adding two integers, a and b. Instead of adding a and b directly, two pointers *pa and *pb are created and the values they are pointing to are added. Fine. I understand that this is for educational purposes and you probably wouldn't use pointers for a basic task like that in real life. But then again StackOverflow seems to agree that you shouldn't use pointers if you can do without them. My problem is that I can hardly think of any situations where you can't use regular variables instead of pointers. In fact several programming languages don't even have pointers, so I'm sure there's always a work-around? Let's say I have a function that changes a variable. I want to change the original variable, so usually I would pass the variable by reference (using a pointer). But if I want to follow StackOverflow's advice and avoid using pointers, I could just pass the variable by value, change it in the function and store the return value in the original variable? So, no pointer needed here? Am I wrong? Am I missing something? Is this all about efficiency, memory management, stack vs heap etc.?