answersLogoWhite

0


Best Answer

pointer is used when we want to retain the change in values between the function calls.

Similarly double pointer is used when we want to retain the change in pointers between the function calls. If you want to modify pointers than you need double pointer to retain the change.

User Avatar

Wiki User

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

Wiki User

14y ago

There is no such thing as Double pointers in C, except in case you're referring to the declaration such as: double *p; But still, this should better be called as pointer to double.

Some people incorrectly call pointer-to-pointer as double pointer.

Pointer-to-pointer holds address of another pointer. So it requires double dereferencing to obtain the value object.

Example:

int **p;

This is a declaration of pointer to pointer for int object.

A pointer-to-pointer requires two pointer de-references to obtain an objects value.

This is often used for linked list manipulation and creating multi-dimensional arrays dynamically.

See related links below for some examples:

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Pointers are required to both store and refer to memory addresses. All programming languages use pass-by-value semantics which means whenever a value is passed to a function that value must be copied to new memory. For primitive data types this isn't a problem because all primitive data types will fit into a single CPU register. But for complex data types this is highly inefficient. For instance, passing an array of 1 million primitives to a function would be inefficient if every primitive had to be copied individually. It is more efficient to simply pass the address of the array itself. This is achieved by passing a pointer, which is itself a primitive and costs virtually nothing to copy. When we pass pointers to functions we get pass-by-reference semantics.

Languages that do not support a native pointer type can still use pass-by-reference semantics using "smart" pointers known as resource handles. A resource handle is simply an object that refers to a value by its memory address. Thus when we pass a complex object to a function, we're actually copying the resource handle, not the value it refers to. Thus we can have two objects referring to the same value in memory.

C++ also supports a reference data type as well as a pointer data type. References are similar to pointers in that they both refer to a memory address, however a pointer is a variable whereas a reference is not. That is, we can store any memory address in a pointer (including nullptr) and thus refer to any object in memory. But a reference is merely an alternative name (an alias) for an existing object; it can never be null and must always refer to the same object throughout its scope. A pointer is a variable in its own right, but a reference is not. As such, a pointer requires memory (storage) of its own thus we can refer to pointers using a pointer-to-pointer type. This adds an additional level of indirection but makes it possible to create arrays of pointers and thus create multi-dimensional arrays in non-contiguous memory. An array of string objects is an example of this; the strings themselves need not be the same length thus we can make better use of memory at the cost of one additional level of indirection. With an array of fixed-length strings we'd get faster access to the strings but we may waste more memory simply to cater for the largest string in the array.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Double pointers are better known as pointer-to-pointer types. You use pointers to store the memory address of an object but when the object is itself a pointer, you need to use a pointer-to-pointer in instead.

Pointer-to-pointer types are typically used when passing pointers into functions. Pointers allow you to pass objects to functions by reference but the pointer itself is passed by value. If you want to pass the pointer by reference, you need to pass a pointer-to-pointer.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Pointer is a variable which points to the address of another variable. Pointers come handy when we are left with no choices such as calling a function using "pass by reference" method, using memory allocated dynamically etc...

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

declaration of a double pointer:

int **pInt;

allocating memory for a double pointer:

pInt = malloc(sizeof(*pInt));

*pInt = malloc(sizeof(*pInt));

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

one is the pointer to apointer where changing it a pointter.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why are pointers needed in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is indirection in c programming?

Example: *(int *)main = 5;


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.


Why pointer is callded jewel of c language?

a pointer is a derived data type in c. pointers are undoubtedly one of the most distinct and exciting features of c language.it has added power and flexibility to the language. *pointers are more efficient in handling arrays and tables. *pointer can be used to support dynamic memory management. *pointers reduce length and complexity of programs. *increase the execution speed and thus reduce the program execution time. by following character's real power of c lies in proper use of pointers. pointer is called the jewel of c-language.


What is Turbo C download used for?

Turbo C is a compiler for a general purpose computer programming language called C. It transforms code written in C into the computer language needed for executable programming.


Is there any pointer called ds cs es ss pointer in C programming?

yes, ds cs es ss are pointers available in c which is used to refer memory segments

Related questions

What is decleration part in C programming?

pointers.


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

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


What are the pointers in computer programming using c?

addresses


What is the need to use pointers in C programming?

find the address


What are pointers in c-programming?

i don't realy have any idea about this but i think its the need of postures


What is indirection in c programming?

Example: *(int *)main = 5;


Which translator is needed for C programming language?

C compiler


Why are header files not required when using far and near pointers?

In C programming, header files are required. It doesn't matter if you are using near pointers, far pointers, both, or neither -- you still need header files. There is no connection between the necessity of header files and the pointers' size.


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.


Is C plus plus good for Embedded programming or not?

C and C++ programming is good for embedded programming. However, embedded implies long running, and that means the possibility of memory fragmentation. You will need to spend time working out or acquiring a method of memory management, such as the use of Smart Pointers and Garbage Collection. This is not a trivial task, but it is a necessary task.


Why pointer is callded jewel of c language?

a pointer is a derived data type in c. pointers are undoubtedly one of the most distinct and exciting features of c language.it has added power and flexibility to the language. *pointers are more efficient in handling arrays and tables. *pointer can be used to support dynamic memory management. *pointers reduce length and complexity of programs. *increase the execution speed and thus reduce the program execution time. by following character's real power of c lies in proper use of pointers. pointer is called the jewel of c-language.


What is Turbo C download used for?

Turbo C is a compiler for a general purpose computer programming language called C. It transforms code written in C into the computer language needed for executable programming.