Advantages of using pointers in C
pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved
pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values
Re: Advantages of using pointers in C
pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved
pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values
Re: Advantages of using pointers in C
[QUOTE=dollysinha;23093]pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved
pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values[/QUOTE]
This was an interesting question. This reminded me to keep in touch with the basics: easy to forget them.
Okay. Here are the advantages of pointers as I see it.
- Pointers allow you to implement sharing without copying i.e. pass by reference v/s pass by copying. This allows a tremendous advantage when you are passing around big arrays as arguments to functions.
- Pointers allow modifications by a function that is not the creator of the memory i.e. function A can allocate the memory and function C can modify it, without using globals, which is a no-no for safe programming.
- Pointers allow us to use dynamic memory allocation.
- Pointers obviously give us the ability to implement complex data structures like linked lists, trees, etc
- Pointers allow ease of programming, especially when dealing with strings. This is due to the fact that a pointer increment will move by the size of the pointee i.e. easy coding to increment to the next memory location of an array, without worrying about how many bytes to move for each data type. I.e. a pointer to a char will move the pointer by a byte, pointer to an int, by the size of the int, etc NOTE that this is important because you do not have to worry about the size of the data types which can vary on different architectures.
- Pointers allow us to resize the data structure whenever needed. For example, if you have an array of size 10, it cannot be resized. But, an array created out of malloc and assigned to a pointer can be resized easily by creating a new memory area through malloc and copying the old contents over. This ability is very important in implementing sparse data structures also.
Well, that is all I can think of.
Re: Advantages of using pointers in C
how many typs of pointers
Re: Advantages of using pointers in C
hi friend..
The topic is vast, you just refer this link to get a clear idea [url=http://en.wikipedia.org/wiki/Pointer]Pointer (computing) - Wikipedia, the free encyclopedia[/url]
Thanks
Deepasree
Re: Advantages of using pointers in C
hi,
hope this link will help you out [url=http://www.cplusplus.com/doc/tutorial/pointers.html]Pointers[/url]
Thanks
Sushma
Re: Advantages of using pointers in C
Pointer is nothing but a variable which stores the address of another variable.while using the pointer we can store any data type suppose using an array we can able to store particular defined data type only but in pointers we can store any datatype.Its like a reference variable.