1. I need explanation for void *ptr=value?
[code=c]
int main()
{
void *the_data;
the_data=20;
// the_data=(int *) 20;
printf("the_dat a now :%d", the_data);
// printf("the_dat a now :%d", *(int*) the_data);
return 0;
}[/code]
When I compile this program in gcc compiler I got the output as
the_data now:20
But I can't do the step I commented, my compiler core dumped.
1. Can a pointer variable directly point a value? How can we call it?
2. I can’t deference it like *(int*) the_data? Why?
3. As I know that void* cannot be deference directly such as *the_data,
What (the_data) pointer contains address or value?
Thanks in advance,
Saravanan.S
[code=c]
int main()
{
void *the_data;
the_data=20;
// the_data=(int *) 20;
printf("the_dat a now :%d", the_data);
// printf("the_dat a now :%d", *(int*) the_data);
return 0;
}[/code]
When I compile this program in gcc compiler I got the output as
the_data now:20
But I can't do the step I commented, my compiler core dumped.
1. Can a pointer variable directly point a value? How can we call it?
2. I can’t deference it like *(int*) the_data? Why?
3. As I know that void* cannot be deference directly such as *the_data,
What (the_data) pointer contains address or value?
Thanks in advance,
Saravanan.S
Comment