Skip to content

Instantly share code, notes, and snippets.

@faustoct1
Last active August 9, 2022 23:47
Show Gist options
  • Save faustoct1/594e1ab710ee06aa371862be7301649b to your computer and use it in GitHub Desktop.
Save faustoct1/594e1ab710ee06aa371862be7301649b to your computer and use it in GitHub Desktop.
Alocar dinamicamente um array com malloc em C
#include <stdio.h>
#include <stdlib.h>
int main(){
int size=5,*array;
array=(int*)malloc(size * sizeof(int));
for(int i=0;i<size;i++){
array[i] = i;
}
for(int i=0;i<size;i++){
printf("dobro de %d é %d\n",i,array[i]*2);
}
free(array);
return 0;
}
@faustoct1
Copy link
Author

Para compilar: gcc -o malloc malloc.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment