Char pointer initialization

I ran into the line below

           char *ch=(char*)3000

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

+3
source share
4 answers

It looks like the ch pointer is assigned the absolute memory address of 3000. As a rule, this is a very bad idea if you are not working with the embedded system without paging, and you know exactly what is in memory 3000.

+9
source

Perhaps viewing the rest of the code would be relevant ...

This pointer may refer to the segment in which it is located (on Intel processors). In this case, it 3000may just be an index into this segment, defined earlier in the program, where we have no lines.

, , , , ( ...).

+1

?

The numerical value "3000" is converted to a char pointer, that is, it is chinitialized to a memory address of 3000 (decimal).

0
source

AFAIK 3000 is not a special address / value, and in most cases access to it will result in a segmentation error or garbage value.

If you see that the code may be incorrectly used instead of (void *), say, in the case of cards where you have key pairs, the result can be cast into an integer in this case.

0
source

Source: https://habr.com/ru/post/1767172/


All Articles