Solved programming problem

How to Scan and Print 1D array with Pointer in C.

Source code

#include<stdio.h>

int main()

{

    int n,i;

    int array[100];

    int *ptr; ///Declaring pointer variable

 

    *ptr=array;///saving the 1st array address in pointer

    printf("Please Enter the Array Size: ");

    scanf("%d",&n);

 

    printf("Please Enter %d Elements: ",n);

    for(i=0;i<n;i++)

    {

        scanf("%d",(ptr+i)); ///scan

    }

    printf("Your Array: ");

    for(i=0;i<n;i++)

    {

      printf("%d ",*(ptr+i)); ///print

    }

    return 0;

}

Output

Please Enter the Array Size:5

Please Enter 5 Elements: 4 3 7 1 9

Your Array: 4 3 7 1 9

 

Join the discussion

Add your comment