Mega Code Archive

 
Categories / C / Code Snippets
 

Pointer comptability

#include <stdio.h> int main(void) { double j = 2.3, k; int *p; /* assign p (an integer pointer) to point to a double. */ p = (int *) &j; /* The next statement does not operate as expected. */ k = *p; /* attempt to assign k the value j through p */ /* The following statement won't output 2.3. */ printf("The (incorrect) value of j is: %f", k); return 0; }