c++ - Which way you prefer to send arguments? -


suppose have function:

void fun(int *a, int *b); 

which way prefer send arguments?

(1.)

int x, y; fun(&x, &y); 

(2.)

int *x, *y; fun(x, y); 

what problems other way or both same , behavior same?

usually use former if want variables on stack, , latter if allocate memory them on heap. stack typically faster, whereas heap typically bigger. in general, use first pattern quite often, , use latter when dealing giant arrays or large objects.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -