Here we will discuss the program process: We declare the function responsible for swapping the two variable values, which takes two integer pointers as parameters and returns any value when it is called. We call the swap function by passing the address of the two variables as arguments using the ampersand symbol. After that, we print the new swapped values of variables. Here we define the swap function content which takes two integer variable addresses as parameters and declare a temporary integer variable used as a third storage box to save one of the value variables which will be put to the second variable.
|Published (Last):||1 March 2014|
|PDF File Size:||5.44 Mb|
|ePub File Size:||7.54 Mb|
|Price:||Free* [*Free Regsitration Required]|
The pointer will be increased or decreased by N times the number of byte s of the type of the variable. Pointers make it easy to access each array element. We can manipulate strings using pointers. Pointers provide an efficient way for accessing the elements of an array structure.
Pointers are used for dynamic memory allocation as well as deallocation. Pointers are used to form complex data structures such as linked list, graph, tree, etc. Disadvantages of Pointers Pointers are a little complex to understand. Pointers can lead to various errors such as segmentation faults or can access a memory location which is not required at all. If an incorrect value is provided to a pointer, it may cause memory corruption.
Pointers are also responsible for memory leakage. Pointers are comparatively slower than that of the variables. Summary A pointer is nothing but a memory location where data is stored. A pointer is used to access the memory location. There are various types of pointers such as a null pointer, wild pointer, void pointer and other types of pointers.
Pointers can be used with array and string to access elements more efficiently. We can create function pointers to invoke a function dynamically. Arithmetic operations can be done on a pointer which is known as pointer arithmetic. Pointers can also point to function which make it easy to call different functions in the case of defining an array of pointers.
When you want to deal different variable data type, you can use a typecast void pointer.
Der Zeiger a zeigt auf die Variable b. Die Speicherstelle des Zeigers a besitzt lediglich die Adresse von b im Beispiel In Zeile 5 wird die Zeigervariable a definiert und eine Variable b vom Typ int. Nach der Definition hat die Zeigervariable a einen nicht definierten Inhalt. Damit zeigt die Variable a nun auf die Variable b.
Subscribe to RSS
Pointer in C
Functions Pointers in C Programming with Examples