This blog is under construction

Saturday 29 June 2013

C program to print address of a variable

Write a C program to print address of a variable.

  #include <stdio.h>
  int main() {
        int data;

        /* get the input from the user */
        printf("Enter value for data:");
        scanf("%d", &data);
        printf("Value of data: %d\n", data);

        /* print the address of the variable */
        printf("Address of data: 0x%x\n", (int)&data);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter value for data:100
  Value of data: 100
  Address of data: 0xbf995a5c



No comments:

Post a Comment