Things about pointers we don’t know
Table of contents
Pointers are used to store another variable’s memory address as its own value. Pointers can be accessed using the asterisk symbol(*).
Here is a simple demonstration of the pointers:-
We can also optimize this code by directly storing the value of address in the initialized pointer value i.e. in *ptr.
“Pointers in Arrays”
In arrays, we can store the addresses of its elements in the pointer variables as well.
Here in the above image we have given *ptr=f in this the base address of the “f” variable we stored in the pointer and in the loop we are incrementing the value of the base address i.e. 4 bytes (as the value of an integer data type is 4bytes)
Let’s suppose the value of the base address is 100 if we give the ptr+1; then the address will get added by four bytes and now the value will be 104 likewise the value will keep on incrementing till the loop finishes and exits.
In Arrays we can write the pointers in many ways some are as follows:-
*ptr[i]
*(ptr+i)
i[ptr]
*(i+ptr)