c++ - Is this the right way to initialize a pointer? -


is right way use function writes pointer? have allocate memory double* before calling function?

double *mydouble; write_to_pointer( mydouble ); 

you can make pointers point data in variety of ways.

the following create single double on heap, , pointed mydub. assign value of mydub 4. delete mydub , set pointer null.

double * mydub = new double; *mydub = 4; delete mydub; mydub = null; 

you can allocate arrays.

double * mydub = new double[123]; mydub[0] = 4; mydub[3] = 43; delete[] mydub; mydub = null; 

and can have pointers point variables exist. (note don't call delete in case!)

double onstack = 4; double * mydub = &onstack; 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -