[Solved] What’s wrong with this code which prints the value at address obtained after converting an integer to an integer pointer [closed]


  1. *((int*)2000) is not “perfectly valid code”. The result of converting an integer to a pointer is implementation-defined. It’s likely that in your implementation, (int*)2000 results in an invalid pointer. Trying to dereference an invalid pointer produces undefined behavior, which means that anything can happen. When you ran the program with the printf line uncommented, it happened to result in a segmentation violation, because the resulting pointer pointed to unaccessible memory. If you’d used some other integer, it might have resulted in a valid pointer, and then you’d see the contents of that memory location.

  2. All the parameters to a function call have to be evaluated before the function is called. The above error is happening while evaluating the parameters to printf(), so the program stops before the function is called. As a result, nothing is printed.

solved What’s wrong with this code which prints the value at address obtained after converting an integer to an integer pointer [closed]