What is "cast from integer to pointer of different size" warning?

​Warnings are issued when the compiler compiles the code and finds something unusual that should be brought to the attention of the programmer.

svg viewer

The compiler issues the “cast from integer to pointer of different size” warning whenever the value of an integer is converted to a pointer, especially when the memory allocated to a pointer is smaller than the memory allocated to an integer data type. For example, if the pointers in a system are stored in 16 bits, but integers are stored in 8 bits, a total of 8 bits would be lost in the given conversion. Hence, a warning is ​issued.​

Data is lost upon conversion from a larger number (int) to a smaller number (pointer).
Data is lost upon conversion from a larger number (int) to a smaller number (pointer).

Code

The following code shows this conversion:

int data = 999; // the integer
int* pointer = &data; // the pointer
pointer = data; // the conversion

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved