Pointers

                           A pointer is a variable whose value is the address of another variable that is the direct address of the memory location. Any variable constant you must declare a pointer before using it to store any valuable address. For example, an integer variable stores an integer value, however, an integer pointer holds the address of an integer variable.



Pointer variable :

                            Int*y=&v;

        Variable: a value stored in a named storage/memory address
      
       Pointer: a variable that points to the storage/memory address of another variable

Declaring a pointer

                      data_type * pointer_variable_name;

           The data_type is the pointers base type of the Cprogram's variable types and indicates the type of the variable this the pointer belongs to. The asterisk ( * : used for multiplication) which is an indirection operator declares a pointer.

Pointer syntax :

                      Pointer = & variable


Program:

#include<stdio.h>

#include<stdlib.h>

int main(){

     int a=100,*b;

     b=&a;

     printf("Address of value:%d",b);

     printf("\nenterd value is :%d",*b);

     return 0;

}

 


online compiler

In this above program, you can see, * symbol which means, specifying name or values.& symbol which is used for finding the memory location value.

Types of pointers :

* Null pointer
* Void pointer
* Wild pointer
* Dangling pointer
* Complex pointer
* Near pointer
* Far pointer
* Huge pointer
Null pointer

the null pointer should not contain any values its only contains empty elements. when you're going to apply this null pointer means, while you are writing the code based on real-life examples or data structure examples. that time you will use this code. Say for example, just think about the linked list it should contain only two parts one is the linked part which is used for linking our node to another node, another one is the data part which contains our values. hereafter linking all the nodes at the last node shouldn't contain any linked part. once we traverse the linked list from starting to the end , at the first part it's having the elements and another one also having the data part. at the last end, we don't have any data to giving the linker so that, on that time our pointer will give null values. which means its don't have no data after the last node.

No comments:

Post a Comment