Last active
August 9, 2022 23:47
-
-
Save faustoct1/594e1ab710ee06aa371862be7301649b to your computer and use it in GitHub Desktop.
Alocar dinamicamente um array com malloc em C
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 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para compilar:
gcc -o malloc malloc.c