Questions tagged [pointer-conversion]

Pointer conversion is a term mostly related to the C and C++ languages, for when a pointer to one type is converted to a pointer of another type.

Pointer conversion is a term mostly related to the C and C++ languages, for when a pointer to one type is converted to a pointer of another type. It could also mean a conversion between pointers with different qualifiers (const, volatile etc), conversions to/from void* or conversions to/from null pointers.

The rules of pointer conversion (C11 6.3.2.3) are slightly different between C and C++. For example, C allows implicit conversions to/from a void pointer and a pointer to another type, while C++ does not allow it. The languages also have different rules for null pointers.

Pointer conversions are also related to function pointers. Function pointers cannot get converted to/from object pointer types, but may in some cases be converted to other function pointer types or to null pointers.

Tag usage:
Any question using shall also be tagged with the relevant language, likely either or . Since these two languages have different pointer conversion rules, both tags should not be used at once, unless the question is explicitly about the difference in pointer conversion rules between the two languages.

33 questions
-2
votes
2 answers

Type conversion with pointers

I'm at a loss to understand how typecasting works with pointers double x = 0.7; int *ptr = (int *)&x; What is happening with *(byte )&x ? &x means the address of variable x. Then what does typecasting an address mean? Can now ptr also refer to x?…
Dubby
  • 1,154
  • 3
  • 16
  • 31
-2
votes
1 answer

reinterpret_cast in C++

uint32_t r,g,b; r = (uint32_t)145; g = (uint32_t)131; b = (uint32_t)139; uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b); float rgbf = *reinterpret_cast(&rgb); uint32_t rgbnew = *(reinterpret_cast
RAM JI GUPTA
  • 47
  • 1
  • 6
-3
votes
1 answer

Pointer casting:can the Pointer has value?

can the Pointer have value?? so In which case is it used int num=100; int* iptr=NULL; iptr=reinterpret_cast(num); printf("%d \n",num); printf("%d \n",num); result 100 100
Tree
  • 7
  • 4
1 2
3