Question

I have come across a line that is given below

           char *ch=(char*)3000

I want to know the meaning of this line .....

No correct solution

OTHER TIPS

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.

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...).

Isn't it obvious?

The numerical value "3000" is cast to a char pointer, i.e. ch is initialized to memory address 3000 (decimal).

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top