To proceed to the next sections in our discussion on C programming language, we should learn the concept of void pointers, i.e. pointers of no specific type, and type casting, i.e. manually changing the data type of a variable. Type conversion can happen automatically (implicitly) or manually (explicitly). The later is termed as type-casting.
Pointers are used extensively in array operations. The name of the array is actually a reference to the address of the first element, rather than the actual array. Thus the array name is a pointer. So when we pass an array as an argument to a function, we are not actually passing a copy of the array (as we do in case of a variable), but we are passing a copy of the pointer to the first element of that array. This is the “pass by reference” hack that we discussed earlier.
To be able to reap the best benefits from pointers, you’ll have to have a deep understanding of them. This blog is going to be very conceptual and we might not be writing real-world value code here, but these program snippets will help you use pointers in a very productive and efficient manner in future. We’ll discuss two use cases of pointers that we generally overlook: strings and the scanf function.
C is a procedural language, which means it follows a series of steps/procedures in a systematic order to solve a problem. These procedures are often organized in functions. These functions take in some value(s) as argument(s), operate on them and return an output. But apart from this approach, a function can even change the state of other variables in the global scope, perform input/output operations etc.
Pointer is something that points to the memory location where the value of a variable is stored. Pointers have data-types. This data-type has nothing to do with the value of the pointer itself, because a pointer has a value which is an address, i.e. a number. So the value of a pointer is always an int.
I still remember those 1st semester ICP classes in my alma mater, Assam Engineering College, when most of the professor’s lecture went above our heads, but the most frustrating topic of all was POINTERS in C. First of all it was a very complex topic to understand and secondly we didn’t even know what was the point of using it.