Created
September 18, 2016 02:40
-
-
Save minostro/654da94d1495f3b4e52739f9cc35ad1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int* initialize_array(int n) { | |
int* array = (int *) malloc(n * sizeof(int)); //allocate memory in the Heap | |
for(int i=0; i<n; i=i+1){ | |
array[i] = i+1; | |
} | |
return array; | |
} | |
int main(int args, char *argv[]) { | |
int array_size; | |
printf("Enter the array size:\n"); | |
scanf("%d", &array_size); | |
int* my_array = initialize_array(array_size); | |
for(int i=0; i<array_size; i=i+1){ | |
printf("value: %i\n", my_array[i]); | |
} | |
free(my_array); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment