answersLogoWhite

0

What are the advantage of pointers in c?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

Pointers are addresses to locations in memory which store data.

Under normal circumstances, memory for variables is already allocated when the program runs. The size of the memory cannot be changed, which is insufficient for some applications.

Hence, memory allocation, reallocation and deallocation functions exist to allow the programmer more freedom in using memory.

Blocks of memory allocated by the program can be easily resized or reallocated for other purposes. For instance, an array declared as follows:

int myarray[20];

has, and will always have, 20 values - it cannot resize, and is known as a static array. However, if you want to be able to resize this array, it's best to redeclare it as an intpointer:

int *myarray=NULL;

Thus, realloc() is the only function necessary for manipulating it:

myarray=(int*)realloc(myarray, sizeof(int)*newarraysize);

Set the new value for newarraysize, and make the above call to resize the array. Then, when you're done with myarray, free(myarray). This is called a dynamic array, since it can be resized dynamically.

Another use of pointers is in linked lists, which are valuable when inserting or removing items to or from arbitrary locations in a list is desired. Allocate the memory for a new node, adjust the variables pointing to the old node to the new node, and free the memory for the old node. Linked lists are faster than arrays in this case, particularly when dealing with large amounts of data.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

The pointer indicates the location of variable . and also *p is indicates the value of the corresponding pointer address....... this is basic advantage of pointers...

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantage of pointers in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the use of learning C?

C and C++ will help you understand the inner workings of a computer with operations such as dealing with memory and pointers. It will do anything that you tell it to do, which is both an advantage and a disadvantage.


What are not advantage of pointers?

The first and the third answer.


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


What is stream pointer in c?

C does not have stream pointers.


What is decleration part in C programming?

pointers.


What is the difference between pointers in c and c plus plus?

Nothing.


Pointers are include in csharp or not?

Yes, you can use pointers in the C#, but to some extent. Links are added with more details.


What are the pointers in computer programming using c?

addresses


What is indirection in c?

Accessing data via pointers.


Which are the possibe arithmetic operation with pointers?

Pointers in C are stored as integers. You can perform any mathematical operations on pointers that you can perform on ints.Of course not, the following operations are possible: =, +, +=, ++, -, -=, --, *, [], ->, typecast


In C you use the concept of pointers whereas there are no pointers used in JAVA why?

Pointers in C are generally the thing that gives learners the most trouble. When C code is not written correctly with respect to pointer use, the resulting bugs can often be very difficult to find and correct. On the other hand, pointers are absolutely necessary in some cases.The designers of Java wanted to make programming easier and hence avoided adding pointers to the language. Java does have object references which accomplish much of what pointers accomplish albeit in a safer way.


How do you write a reverse function in C plus plus without pointers?

You can either use references or you can simply return the result by value. Note that in C++, unlike C, references are not the same as pointers. C++ references are aliases, alternate names for existing objects, whereas pointers are just variables that may contain a memory address that can be dereferenced.