Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To print the input value of a pointer, you need to use the printf function with a format specifier of "%p" instead of "%d" because pointers are memory addresses represented as hexadecimal values. The code would look something like this:

#include <stdio.h>

int main() {
  int *ptr; // declare a pointer variable
  int num = 5; // declare an integer variable

  ptr = &num; // assign the address of num to ptr

  printf("The input value of ptr is: %p\n", (void*)ptr); // use %p format specifier to print the address of num

  return 0;
}

The output would be:

The input value of ptr is: 0x7ffee038d6dc

Note that the actual address value may vary depending on your system. Also, we cast the pointer to void* to avoid a warning, as it is not guaranteed that int* and void* are of the same size.