Continuing on with C – Pointers
The C programming language is a programming languages first created between 1969 and 1973 by Dennis Ritchie and has been the basis of many other programming languages since.
Here we will be carrying on from our initial post “Beginning with C” with a short lesson on pointers
Pointers with C
Pointers are something used in C that make it alot easier to improve your program’s efficiency and allow you to handle unlimited amounts of data.
Using pointers you can have a function that modifies a variable passed to it. You can also dynamically allocate memory, meaning you can handle almost unlimited amounts of data on the fly.
What are pointers?
Pointers as per their name suggests, ‘point’ to places in memory on the machine running the program. The beauty is that one you have assigned a pointer you can simply go to that position in memory and get the data stored in it.
Let’s say you want to pass a massive piece of data to a function, passing the location of this data to the function is a lot easier than copying over all the data.
Pointer Syntax In C
To use pointers in C we need a little bit of new syntax as we need to request both the location in memory of our data and the the value held there. The new syntax is pretty simple though as it only involves the * symbol. An example is shown below:
The * declares the pointer. To access this pointer location in our program all we have to do is use the name of our new pointer variable name without the * and to access the actual value at this location we include the *.
Retrieving the Address
To have a pointer point to another variable we have to have the memory address of the variable too. To get the memory address we need to put the & symbol in front of our variable name.
This is enough for today. If you would like any help with your web or development applications or projects then why not get in contact with us here at Network Intellect.