Skip to content

Instantly share code, notes, and snippets.

@javoperez
Created March 31, 2014 09:46
Show Gist options
  • Save javoperez/9888897 to your computer and use it in GitHub Desktop.
Save javoperez/9888897 to your computer and use it in GitHub Desktop.
malloc, free
#include <stdio.h>
#include <stdlib.h>
void main(void){
int *vector; /*creo el vector a entero*/
int n, i;
printf ("Elementos a introducir:");
scanf ("%d",&n);
vector = malloc( sizeof(int)*n); /* peticion de memoria*/
for ( i= 0; i < n ; i++){
printf ("Elemento %d:", i);
scanf ( "%d", &(vector[i]) );
}
for ( i=0; i < n; i++){
printf("Elemento %d = %d\n",i,vector[i]);
}
free(vector); /*liberación*/
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment