October 22, 2024
Chicago 12, Melborne City, USA
C#

Calculating the allocation needs for malloc(): should code use row*col*sizeof or sizeof*row*col?


Is multiplication order important when allocating?

Even if multiplication may affect things in general, what about common ordering concerns with allocation sizing?

data = malloc(row * col * sizeof data[0]); 
// vs.
data = malloc(sizeof data[0] * row * col); 



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video