answersLogoWhite

0

What are the uses of pointers in c?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

Pointers are used (in the C language) in three different ways:

  • To create dynamic data structures.
  • To pass and handle variable parameters passed to functions.
  • To access information stored in arrays. (Especially if you work with links).

Pointers are also used by experienced programmers to make the code more efficient and thus faster.

So why use pointers? Why don't we use arrays to create data structures?

The answer is simple. With an array you have to declare its maximum size (for every dimension) at the beginning. Let's say you create an array that can hold a maximum of twenty megabytes. When the array is declared, the twenty megabytes is claimed. Now this time you have only data for ten megabytes.

(A next time it could be fifteen megabytes or five megabytes). So in this case ten megabytes of memory is wasted, because only ten megabytes from the twenty is used.

This is where pointers come in. With pointers, you can create dynamic data structures. Instead of claiming the memory up-front, the memory is allocated (from the heap) while the program is running. So the exact amount of memory is claimed and there is no waste. Even better, memory not used will be returned to the heap. (Freed memory can be used for other programs).

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

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

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.


How pointers are used in java?

They aren't. Java uses the (safer) idea of references instead of 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.


What is the need to use pointers in C programming?

find the address