-->
Showing posts with label program to input elements of array and display them using pointer.. Show all posts
Showing posts with label program to input elements of array and display them using pointer.. Show all posts

program to input elements of array and display them using pointer.

using codeblocks
-------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    return 0;
}

---------------------------------------------------------------------------------------------------
or
-------------------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
 
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
   //p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
                                     //array itself is a pointer. It accepts value for first location and so on.
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address
    }
    return 0;
}



------------------------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
getch();
    return 0;
}