Making an array using pointers in c

I think you want to create an array and read data to it and later display it using pointers dynamically.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *A, n;

    printf("\n Enter the size of array : "); // Reading the size of array
    scanf("%d",&n);

    A = (int*) malloc(sizeof(int) * n); // Allocating memory for array 

    int i = 0;

    for(i = 0; i < n; i++) // Reading data to array
        scanf("%d", (A+i));

    // Operations on array

    for(i = 0; i < n; i++) // Printing array
        printf("%d ", A[i]);
    return 0;
}

Hope this help.!!

Leave a Comment