Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
680 B
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#define A 5

int * myArr();

int main()
{
    int arr_size = 5;
//    printf("Enter the size of an array: ");
//    scanf("%d", &arr_size);
    int *ptr;
    ptr = myArr();
    printf("The elements of the array are: \n");

    for(int i = 0; i < arr_size; i++){
        printf("arr[%d] = %d\n", i, *(ptr + i));
    }


    return 0;
}


int * myArr(){
    int arr_size = 5;
    static int arr[A]; // replace A with 5 can work but if replace A with arr_size then cannot

    for(int i = 0; i < arr_size; i++){
        printf("Enter the element %d:", i);
        scanf("%d", &arr[i]);
    }

    return arr;
}