What are Pointers in C Programming ?

-->  As we all know that every variable that is declare in any language has some address or is stored or placed at some memory location, so when it comes to find the address or getting the information of the address of any particular variable where it is located in that situations we cannot fetch using normal variables hence we have a special variable known as Pointer which is used to find locate or point the address / memory location of an type of variable in programming language. Pointers are nothing but basically a container that stores the address(memory location) of another variable and it is also used to point to any memory location. A pointer can also point to any other pointer. It can also store the address of any other pointer too. It is denoted by "*" symbol. Along with this "*" symbol another operator that plays an important part in this topic i.e. "&" it is known as Address operator or Reference operator.


SYNTAX FOR DECLARING POINTER :-


    datatype *pointer_name;

 Example of Pointer : 


#include<stdio.h>
int main()
{
    //declare variables
    int x, y;
    int *ptr;
    //intialization
    x = 100;
    ptr = &x;
    y = *ptr;
    printf("value of x is %d\n", x);
    printf("%d is the address of %u\n", *ptr, ptr);
    printf("%d is the address of %u\n", ptr, &ptr);
    printf("%d is the address of %u\n", y, *(&y));
    return 0;
}


OUTPUT : 




                                 
//ENJOY CODING\\

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post