malloc(n * sizeof *p)
Në shqip: Idioma sizeof *p
ShpjegimiSQ
Mënyra më e sigurt për malloc: int *v = malloc(n * sizeof *v);. Po e ndryshove më vonë tipin e v-së, madhësia përditësohet vetë — s'ke pse e ndryshon në dy vende.
EnglishEN
The safest way to malloc: int *v = malloc(n * sizeof *v);. If you later change v's type, the size updates itself — you don't have to change it in two places.
Si ta mendosh
Si ta matësh kutinë sipas asaj që do të fusësh, jo me një numër të shkruar me dorë.
Lexoje në anglisht
Like sizing the box by what you'll put in it, not by a number written by hand.
Shembull kodic
double *notat = malloc(30 * sizeof *notat);
if (!notat) return 1;