Thread: memory address calculations

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    7

    memory address calculations

    hi again,
    I'm a little bit confused. How do we calculate memory address differences? Does it matter if it's from int or double type variable? Eventually, they are same type of numbers?
    If I give an example like this?
    Code:
    #include <stdio.h>
    
    main() {
        int a=16, b=22;
        int diff_1, diff_2, diff_3, diff_4;
        double c=10.0, d=234.52;
        printf("\nAddress of  a = %u  ",&a);
        printf("Value of a      = %i  ",a);
        printf("\nAddress of  b = %u  ",&b);
        printf("Value of b      = %i  ",b);
        printf("\nAddress of  c = %u  ",&c);
        printf("Value of c      = %f ",c);
        printf("\nAddress of  d = %u  ",&d);
        printf("Value of d      = %f ",d);
    
        printf("\n\n");
        diff_1 = &a-&b;
        diff_2 = &b-&c;
        diff_3 = &c-&d;
        diff_4 = &a-&d;
    
        printf("\nAddress difference a-b = %u", diff_1);
        printf("\nAddress difference b-c = %u", diff_2);
        printf("\nAddress difference c-d = %u", diff_3);
        printf("\nAddress difference a-d = %u", diff_4);
        return 0;
    }
    Thanks.
    Last edited by whynot; 01-26-2022 at 08:58 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2012, 04:28 AM
  2. Finding memory address using memory pattern
    By MindWorX in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2008, 07:20 AM
  3. memory address
    By pktcperlc++java in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2005, 09:15 AM
  4. Memory address?
    By Munkey01 in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 09:04 PM

Tags for this Thread