answersLogoWhite

0


Best Answer

Pointer variables are no different to any other variable. The only difference is that value we store in a pointer variable is a memory address, a reference. Although it is possible to use references alone, there is no guarantee that a reference will always be valid. For instance, if we attempt to allocate a large amount of memory and there isn't a large enough block of free memory to meet that allocation, then we cannot return a reference. References must always refer to something valid. Thus we use a pointer variable instead: if the allocation succeeds, the pointer will contain a reference, otherwise it will contain the value 0 (NULL). Once we know for sure the memory was allocated successfully, we can reference the memory through the pointer.

Although dynamic memory allocation is the main reason for having pointer variables, we can also use pointer variables to point at any valid memory, and refer to that memory in different ways. For instance, if we point to an int variable's reference using a char pointer, then the char pointer can refer to that memory as if it were really just a 1 byte character, rather than a 4 byte integer (just as if we'd cast the int to a char), but we can also increment or decrement the pointer to access any of the four bytes within the integer, just as if it were a 4 element array of type char.

Pointers are also useful in linked structures such as linked lists and trees. Each element in the structure may be allocated non-contiguously and in any sequence (as opposed to an array which always allocates elements contiguously). However we can easily change the order of the elements simply by changing the pointer variables within each element. In an array we have to physically move the elements around, but with a linked structure we only need to update the links to change the order, where each element points to the next element in the sequence, or the previous element, or a parent element or one or more child elements, or any combination as befits the structure. Thus highly complex networks can be generated.

Although working with references is much easier than working with pointer variables, the fact a pointer can be NULL or can point to any reference makes it that much more powerful than a reference. References cannot be changed once instantiated, but pointer variables can. Thus pointers can "walk" through references.

Since functions consume memory just as variables consume memory, pointers can indirectly refer to functions, making it possible to pass functions into functions just as easily as passing variables into functions.

And since pointers are variables with memory allocations of their own, pointers can refer to other pointers. This makes it possible to allocate complex, multi-dimensional arrays in non-contiguous memory, using arrays of pointers to pointers. Although this consumes more memory than a contiguous allocation would, the fact the allocation is broken up into a series of smaller allocations means those allocations will have a far greater chance of being allocated than a single allocation would.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of a pointer variable in c programme. State applications of pointers in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a pointer in programming?

pointers are the variable which stores the address of another variable.


In pointers what is the use of pointer variable?

Pointer is a variable that stores the address of another variable . So pointer basically stores the address of another variable and size of pointer can be evaluated by using sizeof operator.


C program pointers to pointers examples?

Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;


Array of pointers?

a pointer is a variable that contains memory location of another variable.the value u assign to the pointers are memory address of other variable.


What is pointers in c?

a pointer is a variable .it specify the address of the particular variable ,the & symbol is to specify the address of the variable.


What is an array of pointers to pointers?

A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.


What is a ponters in c-programming?

with the help of pointers we able to store the memory location of any variable. In c the pointer variable is use to store the memory location of any variable. The pointer variable is define as a simple variable but in pointer variable use a special "*" character at the left most side of name of pointer variable. If any variable name have * it means it is a pointer variable it hold the memory location of variable.


How many pointers can be used in a c program?

Answergenerally we use simple pointer, void pointer,null pointer, structure pointer. Answerzero or more (unlimited).


How do pointer work in c program?

Pointer can be defined as variable that is used to store memory address , usually the location another variable in memory. Pointers provide a means through which memory location of a variable can be directly accessed.


Is it true or false that assigning an address to a pointer variable is valid operation?

Pointers are meant to store adresses.


What is pointer in java?

There is no concept similar to pointers in Java. Pointers are a feature in C programming using which a programmer can access the memory. This was the cause of major catastrophic programming bugs. The creators of Java excluded this feature just to avoid such catastrophic bugs.


Different types of pointers in c language?

... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.