defining variables int *var and vector()


ignaciolopez
02-23-2006, 11:54 AM
somebody could explain me what is for the definition of a variable with *.

Moreover, what is for the command VECTOR(1,N) wich is included in the library nrutil.h

thanx in advance

nikitos
03-16-2006, 08:53 AM
Variable definition with * means that you've got a pointer to the memory address where your variable located. Memory allocated from the heap at this case and for the oposite case without * variable placed in stack.
VECTOR(1,N), as i understand, mean same as
<type>* vector = new <type>[n+1].
I don't know exactly, because i don't have nrutil.h:(

adp
07-28-2006, 05:47 AM
somebody could explain me what is for the definition of a variable with *.

Moreover, what is for the command VECTOR(1,N) wich is included in the library nrutil.h

thanx in advance

Hi,
if you define a variable vec with
float *vec;
this means you will get a pointer variable to a float data type. Now using this with function vector(1,N) such as,

vec = vector(1,n);
// you can assign values
vec[1]=3.2;
vec[2]=1.2;
//etc..

will give you a vector of size n of type float and the elements of the vector are accessible using vec[1],vec[2], ..., etc to vec[n]. Note that the first element is vec[1] not vec[0] which would have been the case if you have used array such as:

float vec[10]; //you can allocate dynamically using malloc
vec[0]=3.2;
vec[1]=1.2;

now elements of vec are vec[0],vec[1],...,vec[9]

HTH

Dhandapani