-->

storing character in pointe and displaying them

using codeblocks
--------------------------------------------------------------------------------------------------
//understanding array as pointer      //comment of program
//storing character in an array using pointer and displaying them
#include <stdio.h>                     //header file
int main()
{
    char *p;              //character array pointer
    char  a[5];           //CHARACTER ARRAY
    for(p=a;p<a+5;p++)
    {
     printf("address=%d\n",p);// prints 5 addresses

    }
       for(p=a;p<a+5;p++)   //runs the loop from 0 location to 4th location
       {
        *p=getchar();       //gets character
        putchar(*p);        //prints that character
    }

        return 0;
}

/*note:-
p=a------- it takes address of zeroth element
a+5-----------means upto 5th location
p++--------increase the location by 1
----------------------------
while inputting character,
    It accepts one character, then that is replaced by next address.
    Then it is replaced by next address.
    So altogether, we input three characters.
    */
----------------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
//understanding array as pointer      //comment of program
//storing character in an array using pointer and displaying them
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    char *p;              //character array pointer
    char  a[5];           //CHARACTER ARRAY
    for(p=a;p<a+5;p++)
    {
     printf("address=%d\n",p);// prints 5 addresses

    }
       for(p=a;p<a+5;p++)   //runs the loop from 0 location to 4th location
       {
        *p=getchar();       //gets character
        putchar(*p);        //prints that character
    }
       getch();
        return 0;
}

Program to know array as pointer

using codeblocks
----------------------------------------------------------------------------------------------------------
//understanding array as pointer      //comment of program
#include <stdio.h>                     //header file
int main()
{
    int a[]={2,3,4,5,6};                 //array with some values
    int i;
    int *p;
    p=a;                               //assigns base address to pointer
    printf("the address of array=%d\n",p);//prints address of array
    p=&a[0];                            //assigns address of zeroth element
    printf("the address of array=%d\n",p);//prints address of zeroth element
    return 0;
}

//note:- In both cases, we get same address.
//Because computer takes address of array same  as of address of zeroth element.
//So , this array acts as pointer

/*If we want to display all addresses of all elements of an array, then
we write ;click below

https://practisingprograms.blogspot.com/2019/01/program-to-understand-array-as-pointer_12.html


*/

program to understand array as pointer

using codeblocks
----------------------------------------------------------------------------------------------------
//understanding array as pointer      //comment of program
#include <stdio.h>                     //header file
int main()
{
    int a[]={2,3,4,5,6};                 //array with some values
    int i;
    int *p;
    p=a;                               //assigns base address to pointer
    printf("the address of array=%d\n",p);//prints address of array
    p=&a[0];                            //assigns address of zeroth element
    printf("the address of zeroth element of array=%d\n",p);//prints address of zeroth element
    printf("all addresses are\n");
    for(i=0;i<=4;i++)
    {
        printf("location=%d and address=%d\n",i,p+i);//it prints address of respective elements
    }
     printf("values  are\n");
    for(i=0;i<=4;i++)
    {
        printf("location=%d and address=%d\n",i,*(p+i));//it prints value of respective location
    }
    return 0;
}

-------------------------------------------------------------------------------------------------
using turbo c++
---------------------------------------------------------------------------------------------
//understanding array as pointer      //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    int a[]={2,3,4,5,6};                 //array with some values
    int i;
    int *p;
    p=a;                               //assigns base address to pointer
    printf("the address of array=%d\n",p);//prints address of array
    p=&a[0];                            //assigns address of zeroth element
    printf("the address of zeroth element of array=%d\n",p);//prints address of zeroth element
    printf("all addresses are\n");
    for(i=0;i<=4;i++)
    {
        printf("location=%d and address=%d\n",i,p+i);//it prints address of respective elements
    }
     printf("values  are\n");
    for(i=0;i<=4;i++)
    {
        printf("location=%d and address=%d\n",i,*(p+i));//it prints value of respective location
    }
   getch();
    return 0;
}