No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Langage C : malloc?

La fonction malloc permet d'allouer dynamiquement des blocs mémoire.

  • Argument: quantité de mémoire à allouer.
  • Valeur retournée: malloc retourne un pointeur sur le bloc alloué.

Argument de malloc

La fonction malloc demande comme argument la quantité de mémoire à allouer, mais nous ne devons pas oublier que cette quantité de mémoire nécessaire dépend fortement du système porteur. Il ne nous sera donc jamais permis de passer une valeur numérique à la fonction.
Afin de palier à ce problème, nous devons utiliser la fonction sizeof, qui demande en argument le type de donnée, et qui renvoie la taile de la donnée.

Exemple de syntaxe

char *pointeur;
pointeur = (char *) malloc (sizeof (char));

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 19/03/2002, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/c-malloc.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.