Wednesday, 9 April 2014

Use Of Pointer

Pointers  

Pointer are a crucial a piece of C. In the event that you can't utilize pointers appropriately then you have fundamentally lost all the force and adaptability that C permits. The mystery to C is in its utilization of pointers. 

C utilization pointers a considerable measure. Why?: 

It is the best way to express a few reckonings. 

It prepares conservative and effective code. 

It gives a capable device. 

C utilization pointers expressly with: 

Clusters, 

Structures, 

Capacities.

NOTE: Pointers are perhaps the most difficult part of C to understand. C's implementation is slightly different DIFFERENT from other languages.

What is a Pointer?



The unary or monadic driver & gives the ``address of a variable''. 

The indirection or dereference driver * gives the ``contents of an item indicated by a pointer''. 

To proclaim a pointer to a variable do: 

 int *pointer; 


Pointer and Functions

Let us now examine the close relationship between pointers and C's other major parts. We will start with functions.
When C passes arguments to functions it passes them by value.
There are many cases when we may want to alter a passed argument in the function and receive the new value back once to function has finished. Other languages do this (e.g. var parameters in PASCAL). C uses pointers explicitly to do this. Other languages mask the fact that pointers also underpin the implementation of this.
The best way to study this is to look at an example where we must be able to receive changed parameters.
Let us try and write a function to swap variables around?
The usual function call

Pointers and Arrays

Pointers and arrays are very closely linked in C. 
Hint: think of array elements arranged in consecutive memory locations.

Arrays of Pointers

We can have arrays of pointers since pointers are variables. 
Example use
Sort lines of text of different length
NOTE: Text can't be moved or compared in a single operation. 
Arrays of Pointers are a data representation that will cope efficiently and conveniently with variable length text lines. 

"NEWS POWERED BY"

         


Share:

No comments:

Post a Comment

© World Of Programmers All rights reserved | Theme Designed by Seo Blogger Templates