Monday, 31 December 2018

What is use of pointer in C? tccicomputercoaching.com

What is pointer?

Pointer is a variable used to store address of another variable in programming language .

What is the use of Pointer?

The importance of pointers comes with the use of functions. For an example think you code a function to add two values and assign it to the first value. I'll show you how to do it with and without pointers.



Without pointer
int adder(int a, int b){
return a+b;
}
void main()
{
int c = 5;
int d = 6;
c = adder(a,b);
}

So here no use of pointers and this method of using functions is called as call by value. Here value of c 5 and value of d 6 is passed to function adder as a and b and return the value.

So, you should use pointers any place where you need to obtain and pass around the address to a specific spot in memory.

Coding a data structure such as linked list. Without the use of pointers, this becomes an impossible task with C.

Pointer is used to allocate dynamic memory.

Pointers allow you to refer to the same space in memory from multiple locations. This means that you can update memory in one location and the change can be seen from another location in your program.

To learn more about pointer or any concepts of C Programming Language

Visit us @ http://tccicomputercoaching.com/

Call us @ 9825618292

No comments:

Post a Comment