Donate

0 Introduction - pointers


Pointers are a fundamental part of C. If you cannot use pointers properly then you have basically lost all the power and flexibility that C allows. The secret of C is in its use of pointers.
C uses pointers a lot. Why?
It is the only way to express some computations.
It produces compact and efficient code.
It provides a very powerful tool.
C uses pointers explicitly with following:
1. Functions.
2. Arrays.
3. Structures. (discussed later)
Note: Pointers are perhaps the most difficult part of C to understand. C's implementation is slightly different from other languages.
What is a Pointer?
A pointer is a variable which can hold the address of a memory location rather than the value at the location.
Pointer Notation
The actual address of a variable is not known immediately. We can determine the address of the variable using address of operator(&).
We have already seen the use of address of operator in the scanf() function.
Another pointer operator available in C is "*" called "value of address" operator. It gives the value stored at a particular address. This operator is also known as indirection operator.
Pointer Declaration
To declare a pointer to a variable:
int *pointer;
Note: We must associate a pointer to a particular type: You can't assign the address of a short int to a long int,

If you enjoyed this post, make sure you subscribe to my RSS feed!


0 Responses to "Introduction - pointers"

Post a Comment