So where exactly can I apply the concept of pointers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

So where exactly can I apply the concept of pointers

21st Jan 2022, 3:24 PM
Sir Victor Wilfred
Sir Victor Wilfred - avatar
7 Answers
+ 1
Sir Victor Wilfred Here are some use cases that I can think of from my experience: 1. If you wanna modify an object inside a function or a method. You'd need to pass a reference of the object to the function, else if you pass the object directly, the function would actually make a copy of the object and only this copy will be modified without changing the original object. 2. Pointers save space when the object to be passed to a function is pretty large. What if you wanna make a function that requires a large object as its argument but doesn't modify the object itself? You'd need to pass a pointer coz pointers occupy only 8 bytes while objects may occupy a lot more. Saves space ig... 3. Passing functions to functions. This seems weird but, what if you wanna pass a function as the argument to another function? I don't see a way in which you could possibly do this, apart from passing a reference of the function to be used to the function that's gonna receive it. 4. Arrays. It's self-explanatory, ain't it?
21st Jan 2022, 3:46 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Wow quite a lot of stuff to grasp there but it makes sense, thanks
21st Jan 2022, 4:16 PM
Sir Victor Wilfred
Sir Victor Wilfred - avatar
+ 1
Another question, is it really worth it learning C at this era or should I move on to C++ or C#
21st Jan 2022, 4:29 PM
Sir Victor Wilfred
Sir Victor Wilfred - avatar
0
Sir Victor Wilfred Oh, and virtual functions in Cpp. Saves a lot of time just using the parent object pointer instead of manually typing out all of the inherited class names.
21st Jan 2022, 3:51 PM
Œ ㅤ
Œ ㅤ - avatar
0
Sir Victor Wilfred Pointers will start to be useful when you're starting to gather enough experience with the language. Till then, might seem a bit redundant and unnecessary but that'll soon prove to be superficial. Regarding your question, depends. One thing that I have learnt is that learning the other languages will be a lot easier once you know a basic, "mother" language like C. You'll get to know more about the low-level stuff this way. I recommend you to start the C course in SL before moving on with C++. C# is a different story, because it's a higher level language that doesn't expose what's going on inside the system. But it's alright if you aren't planning to know about the workings of the machine. I recommend you to learn about a lower-level language like C before moving on to the higher-level ones like Java, C# and Python.
21st Jan 2022, 5:21 PM
Œ ㅤ
Œ ㅤ - avatar
0
Sir Victor Wilfred Regarding the advantages of C over the others, time (as good as thirty times faster than Python) and memory efficiency are all I could possibly think of. The disadvantage is that it takes a bit more work to make something using C as compared to Python which does most stuff automatically.
21st Jan 2022, 5:26 PM
Œ ㅤ
Œ ㅤ - avatar