Skip to content

Instantly share code, notes, and snippets.

@minostro
Created September 18, 2016 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minostro/654da94d1495f3b4e52739f9cc35ad1b to your computer and use it in GitHub Desktop.
Save minostro/654da94d1495f3b4e52739f9cc35ad1b to your computer and use it in GitHub Desktop.
#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