Manuals and instructions for everything

why do we need pointers in programming

Pointers are necessary for dynamic memory location, many data structures, and efficient handling of large amounts of data. Without pointers, you'd have to allocate all the program data globally or in functions or the equivalent, and you'd have no recourse if the amount of data grew beyond what you had originally allowed for. I hesitate to use absolutes here, but as far as I know all modern computer languages have pointers in some form or other. In most languages that use pointers, there are certain sorts of references that are pointers, and perhaps certain sorts of references that aren't, and there is no further notational difference. A Lisp
cell is a pair of pointers, although a is not a pointer. In Java, the variable used for the instance of a class is a pointer, but an isn't. The language syntax doesn't reflect that. C is unusual in that pointers are optional, explicit, and allow explicit pointer arithmetic. It is perfectly possible to write, and once you've allocated memory for s. Since pointers are optional, it is useful to have notational differences. (It's essential in C++ for smart pointers, as given, bar. reset() is likely to have a much different one. ) (Actually, explicit pointers were often used in other languages when C was originally being developed, such as in Pascal.

C is an older language than most in common use today, and it shows. ) One of C's design goals was to write Unix in, and therefore it needed to handle memory locations in a detailed manner. (C is actually one of a family of system implementation languages common when it was being designed, another example being Cybol for Control Data computers. C is the one that became a big hit. ) Therefore, it is possible to manipulate C pointers directly, assigning memory addresses and calculating new ones. This also led to some design decisions in C. C arrays are based heavily on pointer arithmetic, and indeed an array decays into a pointer in very many situations. Passing variables to C functions by reference is done by pointer. There was no strong need for arrays and passing variables by reference in the form that other contemporary languages had, so C didn't get those. So, the answer is that, in most languages nowadays, you use pointers constantly without being reminded of the fact. In C, and to a lesser extent C++, you use pointers either to do low-level things, or as accomplish higher-level things that there's no special notation for. Back in those days, developers were working much closer to the metal.

C was essentially a higher level replacement for assembly, which is almost as close to the hardware as you can get, so it was natural you needed pointers to be efficient in solving coding problems. However, pointers are sharp tools, which can cause great damage if used carelessly. Also, direct use of pointers open up the possibility to many security problems, which weren't an issue back then (in 1970, the internet consisted of about a few dozen machines across a couple of universities, and it was not even called like that. ), but became more and more important since. So nowadays higher level languages are consciously designed to avoid raw memory pointers. Saying that "advanced things done in VB. Net or Java are not possible in C" shows a very limited point of view, to say the least :-) First of all, all of these languages (even assembly) are Turing complete so in theory whatever is possible in one language, is possible in all. Just think about what happens when a piece of VB. Net or Java code is compiled and executed: eventually, it is translated into (or mapped to) machine code, because that is the only thing which the machine understands. In compiled languages like C and C++, you can actually get the full body of machine code equivalent to the original higher level source code, as one or more executable files/libraries.

In VM based languages, it is more tricky (and may not even be possible) to get the entire equivalent machine code representation of your program, but still eventually it is there somewhere, within the deep recesses of the runtime system and the JIT. Now, of course, it is an entirely different question whether some solution is feasible in a specific language. No sensible developer would start writing a web app in assembly :-) But it is useful to bear in mind that most or all of those higher level languages are built on top of a huge amount of runtime and class library code, a large chunk of which is implemented in a lower level language, typically in C. So to get to the question, Do you think knowledge on pointers to the young people [. ] is important? The concept behind pointers is indirection. This is a very important concept and IMHO every good programmer should grasp it on a certain level. Even if someone is working solely with higher level languages, indirection and references are still important. Failing to understand this means being unable to use a whole class of very potent tools, seriously limiting one's problem solving ability in the long run.

So my answer is yes, if you want to become a truly good programmer, you must understand pointers too (as well as recursion - this is the other typical stumbling block for budding developers). You may not need to start with it - I don't think C is optimal as a first language nowadays. But at some point one should get familiar with indirection. Without it, we can never understand how the tools, libraries and frameworks we are using actually work. And a craftsman who doesn't understand how his/her tools work is a very limited one. Fair enough, one may get a grasp of it in higher level programming languages too. One good litmus test is correctly implementing a doubly linked list - if you can do it in your favourite language, you can claim you understand indirection well enough. But if not for anything else, we should do it to learn respect for the programmers of old who managed to build unbelievable things using the ridiculously simple tools they had (compared to what we have now). We are all standing on the shoulders of giants, and it does good to us to acknowledge this, rather than pretending we are the giants ourselves.

  • Views: 99

why do you want to join banking sector
why do we use pointers in c at all
why do we use arrays in c
why do we need pointers in programming
why operator overloading is not supported in java
why we use string args in main method in java
why do you want to work in a banking industry