One thought on “What are pointers used for in real life?

  1. Arti says:

    E. Fine. I want to change the original variable, so usually I would pass the variable by reference (using a pointer). Time for a noob question. almost every tutorial teaches you how to use pointers by using them for really basic things like adding two integers, a and b. But then again StackOverflow seems to agree that you shouldn't use pointers if you can do without them. g. 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 I'm still struggling with when I'm supposed to use pointers instead of "regular" variables. I know what pointers are and how they are used. 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. 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 a fewthing? Is this all about efficiency, memory management, stack vs heap etc. Instead of adding a and b directly, two pointers *pa and *pb are created and the values they are pointing to are added. My problem is that I can hardly think of any situations where you can't use regular variables instead of pointers.

Leave a Reply

Your email address will not be published. Required fields are marked *