-->

program to understand array of pointer

using codeblocks
---------------------------------------------------------------------------------------------------------
//understanding array of pointers  for numbers     //title of program
#include <stdio.h>                    //header file

int main()
{
    int a[4],i;
    int *p[4];                        //pointer to store 4 addresses
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter element for location %d\n",i);
        scanf("%d",&a[i]);           // gets array elements
    }
    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,p[i]);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,*p[i]);//prints the value
    }
    return 0;
}

---------------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------
//understanding array of pointers  for numbers     //title of program
#include <stdio.h>                    //header file
#include<conio.h>

int main()
{
    int a[4],i;
    int *p[4];                        //pointer to store 4 addresses
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter element for location %d\n",i);
        scanf("%d",&a[i]);           // gets array elements
    }
    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,p[i]);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,*p[i]);//prints the value
    }
getch();
    return 0;
}

No comments:

Post a Comment