error runing simple code

Hi
l am trying to run this simple code , l get a error which l don't understand why
so that l can solve it .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

void main()
{

	double value1; 
	double value2=20000;  

	long *Iptr;
	long obj;  
	Iptr=&obj; 
	*Iptr=&value1;  
	printf("%d",*Iptr);  
	value2=*Iptr; 
	printf("%d",value2); 
	printf("%d",&value1); 
	printf("%d",Iptr);   
}


The error :
--------------------Configuration: problema 3 final - Win32 Debug--------------------
Compiling...
problema 3 final.cpp
C:\problema 3 final.cpp(12) : error C2440: '=' : cannot convert from 'double *' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
Last edited on
Interpret your error message and you will know what went wrong. It says in the file "problema 3 final.cpp" on line 12 there was an error converting from a double pointer (&value1) to a long value (*Iptr):
*Iptr=&value1;

You cannot convert a pointer to a long value without a cast:
*Iptr = (long) &value1;
or
*Iptr = reinterpret_cast<long> (&value1);
should fix your problem.

Also, you should be using `int main()' instead of `void main()'.
THANKS YOU !
actually l dont know what cast is , l even don't know what conversion is .
and why should l do it .

all l wanted to store the memory address of the variable value1 into another value called obj
but l had to do so using a pointers , as far as l know " *Iptr"= obj .
so that should do it . isn't it right?
I think you complicated things a bit too much. Why aren't you using a double pointer rather than a long pointer (double * instead of long *)? That would eliminate the need for `obj' to exist at all.
Last edited on
Topic archived. No new replies allowed.