Skip to content

Instantly share code, notes, and snippets.

@Mach12
Last active October 7, 2015 08:47
Show Gist options
  • Save Mach12/7cafe77a7c9eba159345 to your computer and use it in GitHub Desktop.
Save Mach12/7cafe77a7c9eba159345 to your computer and use it in GitHub Desktop.
Exemple d'utilisation array vs pointeur
#include <stdlib>
int main()
{
// Exactement la même chose
// sauf que le 2e est alloué
int someArray[10];
int* somePointer = malloc( sizeof(int) * 10 );
// Changer la taille de somePointer
somePointer = realloc(somePointer, sizeof(int) * 15);
// Ca c'est valide:
someArray[8] = 2;
// Et ça aussi
somePointer[12] = 15;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment