1

In the cppreference below there are usages of static_cast to cast int* to void*, https://en.cppreference.com/w/cpp/memory/c/aligned_alloc . What the program on the URL does is first declaring two pointers (p1 and p2 of int*) and then dynamically allocating the memory using either malloc or aligned_alloc. To see the memory alignment, it also shows the addresses of allocated memory. This is ok for now.

However, there exist static_cast<void*>(p1) and static_cast<void*>(p2) to show the memory addresses. Why are those cast needed? I confirmed that without this casting, p1 and p2 themselves show the memory addresses (probably aligned or unaligned, depending on use of malloc or alligned_alloc). For each pointer, an address shown is not different regardless of use of the casting...

user9414424
  • 498
  • 3
  • 15

0 Answers0