Dereferencing a const double* array, how?

Nov 2, 2011 at 3:50pm
Hi!

I have a variable that is declared as "const double* value_of_interest", so that the data pointed to by value_of_interest (an adress) is a constant. Now I want to know the value at that address by using the dereferencing operator * on tmp.

More specific "value_of_interest" is an array that contains a certain amount of elements, which are stored all at the same address.

Function prototype:

void function(int& bla1, int* bla2, int* bla3, const double* value_of_interest, int bla5) { }

Function call:

function(arg1, arg2, arg3, tmp, arg5);

So I want to find every value in tmp by accessing it like: *(tmp+i), but that does not seem to work.

Can anyone help me out?

Thanks in advance!
Last edited on Nov 2, 2011 at 3:55pm
Nov 2, 2011 at 4:54pm
How does it not work? (post the error message)
Also, note that *(value_of_interest+i) is equivalent to value_of_interest[i].
Last edited on Nov 2, 2011 at 4:55pm
Nov 2, 2011 at 5:19pm
It should work .. what are the error you are getting or what is the output you are getting .
Nov 2, 2011 at 5:22pm
When I print the value of measure inside my function, I get the right values. Now I try to print them outside the function with:

mexPrintf("measure = %d\n",*(tmp+i));

But it gives me the address (I think) instead of the value... It's not an error message, but just a wrong result (not what I want)...
Last edited on Nov 3, 2011 at 2:31pm
Nov 2, 2011 at 7:09pm
I don't see how that worked at all. That "%d" in printf has a meaning - it says that the argument is an integer and you want it printed in decimal. To print a double, write "%f".
Nov 2, 2011 at 11:35pm
Thanks for pointing that out hamsterman, it solved my problem! What a stupid mistake! :)
Topic archived. No new replies allowed.