Using pointer memory

Perhaps I am mistaken in these facts, so correct me!

The pointer points to a memory address; if you go to this memory address, will you find a byte? The pointer also points to the smallest memory segment address that it points to, so if it points to a memory segment with 8 bytes that starts at 0x0 and ends at 0x7, will it point to 0x0?

How does a pointer know the size of the memory it points to? So, if the pointer points to a 128-byte memory segment and the pointer is converted to another type, what happens with the size of the memory segment?

+4
source share
2 answers

How does a pointer know the size of the memory it points to?

This is not true.

, 128 , , ?

, , , , , . . .

sizeof char* :

std::ofstream os("some-binary-file");
const double d = 0.1234;

os.write((char*)&d, sizeof(double));
//                  ^^^^^^^^^^^^^^
// 
// Otherwise os.write has no way of knowing how much to write

, double*, , "" sizeof(double) . , .

tl; dr: , , , - .

+8

, ?

( void *) . , . , , .

, void * , .

+2

All Articles