hi i have come across a line that is given below
char *ch=(char*)3000
i want to know the meaning of this line .....
hi i have come across a line that is given below
char *ch=(char*)3000
i want to know the meaning of this line .....
Isn't it obvious?
The numerical value "3000" is cast to a char pointer, i.e. ch
is initialized to memory address 3000 (decimal).
It's stating assign the pointer a value of 3000. Hence, it's saying that the pointer should point to the memory address signified by the value of 3000. This dangerous.
It looks like the pointer, ch, is being assigned an absolute memory address 3000. Generally a very bad idea, unless you're working on an embedded system with no paging and you know exactly what's at memory location 3000.
AFAIK, 3000 is no special address/value, and In most of the cases accessing it would result in segmentation fault or a garbage value.
If you see that in code, may be it is incorrectly used instead of a (void*), say in case of maps where you have key value pairs, the result may be cast into an integer in that case.
Maybe seeing the rest of the code would be relevant...
That pointer could be relative to the segment in which it resides (on Intel processors). In this case the 3000
could be simply an index into that segment, defined earlier in the program, where we don't have the lines.
This depends upon the system architecture, the environment, the OS, the compiler, the rest of the code (and the programmer...).