Use scanf() to read a memory address - C Language Basics

C examples for Language Basics:scanf

Introduction

To input a memory address, use the %p format specifier.

scanf() with %p can read an address in the format defined by the CPU.

For example, this program inputs an address and then displays what is at that memory address:

Demo Code

#include <stdio.h>

int main(void)
{
   char *p;//from  www.  ja  v a2s  .co  m

   printf("Enter an address: ");
   scanf("%p", &p);
   printf("Value at location %p is %c\n", p, *p);

   return 0;
}

Result


Related Tutorials