Wednesday, 15 August 2012

c++ - Can I use the static keyword to only allocate new memory once? -



c++ - Can I use the static keyword to only allocate new memory once? -

say have function run multiple times. function includes code below:

static int *hello = new int;

will hello allocated first time run?

yes, allocated once.

but allow me suggest else. suppose have function that:

int* get_static_hello() { static int* value = new int; homecoming value; }

well, next (it 1 hundred percent correct):

int* get_static_hello() { static int value; homecoming &value; }

c++ static keyword

No comments:

Post a Comment