Last active
October 7, 2015 08:47
Exemple d'utilisation array vs pointeur
This file contains hidden or 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 <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